Spaces:
Sleeping
Sleeping
TuringsSolutions
commited on
Commit
•
9ede33d
1
Parent(s):
9b4d9ff
Update app.py
Browse files
app.py
CHANGED
@@ -20,7 +20,7 @@ def llava(inputs, history):
|
|
20 |
return processed
|
21 |
|
22 |
def respond(message, history):
|
23 |
-
"""Generate a response
|
24 |
if "files" in message and message["files"]:
|
25 |
inputs = llava(message, history)
|
26 |
streamer = TextIteratorStreamer(skip_prompt=True, skip_special_tokens=True)
|
@@ -44,31 +44,40 @@ def generate_image(prompt):
|
|
44 |
client = InferenceClient("KingNish/Image-Gen-Pro")
|
45 |
return client.predict("Image Generation", None, prompt, api_name="/image_gen_pro")
|
46 |
|
|
|
|
|
|
|
|
|
|
|
47 |
# Gradio app setup
|
48 |
with gr.Blocks(title="AI Chat & Tools") as demo:
|
|
|
|
|
49 |
with gr.Row():
|
50 |
with gr.Column(scale=1, min_width=200):
|
51 |
gr.Markdown("## Navigation")
|
52 |
-
gr.Button("Chat Interface")
|
53 |
-
gr.Button("Image Generation")
|
54 |
-
|
55 |
with gr.Column(scale=3):
|
56 |
-
with gr.
|
57 |
gr.Markdown("## Chat with AI Assistant")
|
58 |
chatbot = gr.Chatbot(label="Chat", show_label=False)
|
59 |
-
|
60 |
-
|
61 |
-
file_input = gr.File(label="Upload an image", file_types=["image/*"])
|
62 |
-
|
63 |
text_input.submit(respond, [text_input, chatbot], [chatbot])
|
64 |
file_input.change(respond, [file_input, chatbot], [chatbot])
|
65 |
-
|
66 |
-
with gr.
|
67 |
gr.Markdown("## Image Generator")
|
68 |
image_prompt = gr.Textbox(placeholder="Describe the image to generate", show_label=False)
|
69 |
image_output = gr.Image(label="Generated Image")
|
70 |
-
|
71 |
image_prompt.submit(generate_image, [image_prompt], [image_output])
|
72 |
|
|
|
|
|
|
|
|
|
73 |
# Launch the app
|
74 |
demo.launch()
|
|
|
|
20 |
return processed
|
21 |
|
22 |
def respond(message, history):
|
23 |
+
"""Generate a response for input."""
|
24 |
if "files" in message and message["files"]:
|
25 |
inputs = llava(message, history)
|
26 |
streamer = TextIteratorStreamer(skip_prompt=True, skip_special_tokens=True)
|
|
|
44 |
client = InferenceClient("KingNish/Image-Gen-Pro")
|
45 |
return client.predict("Image Generation", None, prompt, api_name="/image_gen_pro")
|
46 |
|
47 |
+
# State management to control visibility
|
48 |
+
def show_page(page, state):
|
49 |
+
"""Updates the state to show the selected page."""
|
50 |
+
return {"chat_visible": page == "chat", "image_visible": page == "image"}
|
51 |
+
|
52 |
# Gradio app setup
|
53 |
with gr.Blocks(title="AI Chat & Tools") as demo:
|
54 |
+
state = gr.State({"chat_visible": True, "image_visible": False})
|
55 |
+
|
56 |
with gr.Row():
|
57 |
with gr.Column(scale=1, min_width=200):
|
58 |
gr.Markdown("## Navigation")
|
59 |
+
chat_button = gr.Button("Chat Interface")
|
60 |
+
image_button = gr.Button("Image Generation")
|
61 |
+
|
62 |
with gr.Column(scale=3):
|
63 |
+
with gr.Row(visible=lambda state: state["chat_visible"], interactive=True):
|
64 |
gr.Markdown("## Chat with AI Assistant")
|
65 |
chatbot = gr.Chatbot(label="Chat", show_label=False)
|
66 |
+
text_input = gr.Textbox(placeholder="Enter your message...", lines=2, show_label=False)
|
67 |
+
file_input = gr.File(label="Upload an image", file_types=["image/*"])
|
|
|
|
|
68 |
text_input.submit(respond, [text_input, chatbot], [chatbot])
|
69 |
file_input.change(respond, [file_input, chatbot], [chatbot])
|
70 |
+
|
71 |
+
with gr.Row(visible=lambda state: state["image_visible"], interactive=True):
|
72 |
gr.Markdown("## Image Generator")
|
73 |
image_prompt = gr.Textbox(placeholder="Describe the image to generate", show_label=False)
|
74 |
image_output = gr.Image(label="Generated Image")
|
|
|
75 |
image_prompt.submit(generate_image, [image_prompt], [image_output])
|
76 |
|
77 |
+
# Button actions to switch between pages
|
78 |
+
chat_button.click(lambda: show_page("chat", state.value), None, state)
|
79 |
+
image_button.click(lambda: show_page("image", state.value), None, state)
|
80 |
+
|
81 |
# Launch the app
|
82 |
demo.launch()
|
83 |
+
|