Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -1,42 +1,49 @@
|
|
1 |
-
import torch
|
2 |
-
from diffusers import StableDiffusionPipeline
|
3 |
import gradio as gr
|
4 |
-
|
5 |
-
|
6 |
-
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
28 |
with gr.Row():
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
|
|
|
|
|
|
|
1 |
import gradio as gr
|
2 |
+
import torch
|
3 |
+
from transformers import AutoModelForCausalLM, AutoTokenizer
|
4 |
+
import os
|
5 |
+
|
6 |
+
# Set model and tokenizer
|
7 |
+
model_name = "Qwen/Qwen2.5-Omni-3B"
|
8 |
+
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
9 |
+
model = AutoModelForCausalLM.from_pretrained(model_name, torch_dtype=torch.bfloat16, device_map="auto")
|
10 |
+
|
11 |
+
# Function to process inputs and generate response
|
12 |
+
def process_input(text_input, image_input=None, audio_input=None):
|
13 |
+
inputs = {"text": text_input}
|
14 |
+
if image_input:
|
15 |
+
inputs["image"] = image_input
|
16 |
+
if audio_input:
|
17 |
+
inputs["audio"] = audio_input
|
18 |
+
|
19 |
+
# Tokenize inputs (simplified for demo)
|
20 |
+
input_ids = tokenizer.encode(inputs["text"], return_tensors="pt").to(model.device)
|
21 |
+
|
22 |
+
# Generate response
|
23 |
+
outputs = model.generate(input_ids, max_length=200)
|
24 |
+
response_text = tokenizer.decode(outputs[0], skip_special_tokens=True)
|
25 |
+
|
26 |
+
# Placeholder for speech generation (requires additional setup)
|
27 |
+
response_audio = None # Implement speech generation if needed
|
28 |
+
|
29 |
+
return response_text, response_audio
|
30 |
+
|
31 |
+
# Gradio interface
|
32 |
+
with gr.Blocks() as demo:
|
33 |
+
gr.Markdown("# Qwen2.5-Omni-3B Demo")
|
34 |
with gr.Row():
|
35 |
+
text_input = gr.Textbox(label="Text Input")
|
36 |
+
image_input = gr.Image(label="Upload Image")
|
37 |
+
audio_input = gr.Audio(label="Upload Audio")
|
38 |
+
submit_button = gr.Button("Submit")
|
39 |
+
text_output = gr.Textbox(label="Text Response")
|
40 |
+
audio_output = gr.Audio(label="Audio Response")
|
41 |
+
|
42 |
+
submit_button.click(
|
43 |
+
fn=process_input,
|
44 |
+
inputs=[text_input, image_input, audio_input],
|
45 |
+
outputs=[text_output, audio_output]
|
46 |
+
)
|
47 |
+
|
48 |
+
# Launch the app
|
49 |
+
demo.launch()
|