Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
@@ -1,51 +1,74 @@
|
|
1 |
import os
|
2 |
-
os.environ["HF_HUB_DISABLE_TELEMETRY"] = "1"
|
3 |
-
os.environ["HF_HUB_ENABLE_HF_TRANSFER"] = "1"
|
4 |
import gradio as gr
|
5 |
from multimodal_module import MultiModalChatModule
|
6 |
import asyncio
|
7 |
|
8 |
-
|
|
|
9 |
|
10 |
-
|
11 |
-
|
|
|
12 |
|
13 |
-
def
|
14 |
-
|
|
|
15 |
|
16 |
-
|
17 |
-
return
|
18 |
|
19 |
-
def
|
20 |
-
return asyncio.run(
|
21 |
|
22 |
-
|
23 |
-
return
|
24 |
|
25 |
-
def
|
26 |
-
return asyncio.run(
|
|
|
|
|
|
|
|
|
27 |
|
28 |
-
with gr.Blocks() as
|
29 |
-
gr.Markdown("
|
30 |
|
31 |
-
with gr.Tab("Text Chat"):
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
gr.
|
|
|
37 |
|
38 |
-
with gr.Tab("Voice"):
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
gr.Button("Process")
|
43 |
|
44 |
-
with gr.Tab("
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
import os
|
|
|
|
|
2 |
import gradio as gr
|
3 |
from multimodal_module import MultiModalChatModule
|
4 |
import asyncio
|
5 |
|
6 |
+
# Initialize module
|
7 |
+
mm = MultiModalChatModule()
|
8 |
|
9 |
+
# Environment configuration
|
10 |
+
os.environ["HF_HUB_DISABLE_TELEMETRY"] = "1"
|
11 |
+
os.environ["TOKENIZERS_PARALLELISM"] = "false"
|
12 |
|
13 |
+
async def async_wrapper(fn, *args):
|
14 |
+
"""Handle async calls from Gradio"""
|
15 |
+
return await fn(*args)
|
16 |
|
17 |
+
def process_voice(audio, user_id):
|
18 |
+
return asyncio.run(async_wrapper(mm.process_voice_message, audio, int(user_id)))
|
19 |
|
20 |
+
def process_image(image, user_id):
|
21 |
+
return asyncio.run(async_wrapper(mm.process_image_message, image, int(user_id)))
|
22 |
|
23 |
+
def chat(text, user_id, lang):
|
24 |
+
return asyncio.run(async_wrapper(mm.generate_response, text, int(user_id), lang))
|
25 |
|
26 |
+
def generate_image(prompt, user_id):
|
27 |
+
return asyncio.run(async_wrapper(
|
28 |
+
mm.generate_image_from_text,
|
29 |
+
prompt,
|
30 |
+
int(user_id)
|
31 |
+
))
|
32 |
|
33 |
+
with gr.Blocks(title="Multimodal AI Assistant") as app:
|
34 |
+
gr.Markdown("## ๐ Multimodal AI Assistant")
|
35 |
|
36 |
+
with gr.Tab("๐ฌ Text Chat"):
|
37 |
+
with gr.Row():
|
38 |
+
user_id = gr.Textbox(label="User ID", value="123")
|
39 |
+
lang = gr.Dropdown(["en", "es", "fr", "de"], label="Language", value="en")
|
40 |
+
chat_input = gr.Textbox(label="Your Message")
|
41 |
+
chat_output = gr.Textbox(label="AI Response", interactive=False)
|
42 |
+
chat_btn = gr.Button("Send")
|
43 |
|
44 |
+
with gr.Tab("๐๏ธ Voice"):
|
45 |
+
voice_input = gr.Audio(sources=["microphone", "upload"], type="filepath")
|
46 |
+
voice_user = gr.Textbox(label="User ID", value="123")
|
47 |
+
voice_output = gr.JSON(label="Analysis Results")
|
48 |
+
voice_btn = gr.Button("Process")
|
49 |
|
50 |
+
with gr.Tab("๐ผ๏ธ Images"):
|
51 |
+
with gr.Tab("Describe"):
|
52 |
+
img_input = gr.Image(type="filepath")
|
53 |
+
img_user = gr.Textbox(label="User ID", value="123")
|
54 |
+
img_output = gr.Textbox(label="Description")
|
55 |
+
img_btn = gr.Button("Describe")
|
56 |
+
|
57 |
+
with gr.Tab("Generate"):
|
58 |
+
gen_prompt = gr.Textbox(label="Prompt")
|
59 |
+
gen_user = gr.Textbox(label="User ID", value="123")
|
60 |
+
gen_output = gr.Image(label="Generated Image")
|
61 |
+
gen_btn = gr.Button("Generate")
|
62 |
+
|
63 |
+
# Event handlers
|
64 |
+
chat_btn.click(chat, [chat_input, user_id, lang], chat_output)
|
65 |
+
voice_btn.click(process_voice, [voice_input, voice_user], voice_output)
|
66 |
+
img_btn.click(process_image, [img_input, img_user], img_output)
|
67 |
+
gen_btn.click(generate_image, [gen_prompt, gen_user], gen_output)
|
68 |
+
|
69 |
+
if __name__ == "__main__":
|
70 |
+
app.launch(
|
71 |
+
server_name="0.0.0.0",
|
72 |
+
server_port=7860,
|
73 |
+
share=False
|
74 |
+
)
|