Spaces:
Paused
Paused
Update app.py
Browse files
app.py
CHANGED
@@ -8,7 +8,6 @@ import secrets
|
|
8 |
from pathlib import Path
|
9 |
from pydub import AudioSegment
|
10 |
|
11 |
-
# Initialize the model and tokenizer
|
12 |
torch.manual_seed(420)
|
13 |
tokenizer = AutoTokenizer.from_pretrained("Qwen/Qwen-Audio-Chat", trust_remote_code=True)
|
14 |
model = AutoModelForCausalLM.from_pretrained("Qwen/Qwen-Audio-Chat", device_map="cuda", trust_remote_code=True).eval()
|
@@ -45,6 +44,8 @@ def _parse_text(text):
|
|
45 |
return text
|
46 |
|
47 |
def predict(_chatbot, task_history, user_input):
|
|
|
|
|
48 |
print("Predict - Start: task_history =", task_history)
|
49 |
if not isinstance(task_history, list) or not all(isinstance(item, tuple) and len(item) == 2 for item in task_history):
|
50 |
print("Error: task_history should be a list of tuples of length 2.")
|
@@ -107,6 +108,8 @@ def predict(_chatbot, task_history, user_input):
|
|
107 |
|
108 |
|
109 |
def regenerate(_chatbot, task_history):
|
|
|
|
|
110 |
print("Regenerate - Start: task_history =", task_history)
|
111 |
if not task_history:
|
112 |
return _chatbot
|
@@ -123,6 +126,8 @@ def regenerate(_chatbot, task_history):
|
|
123 |
return predict(_chatbot, task_history)
|
124 |
|
125 |
def add_text(history, task_history, text):
|
|
|
|
|
126 |
print("Add Text - Before: task_history =", task_history)
|
127 |
if not isinstance(task_history, list):
|
128 |
task_history = []
|
@@ -132,6 +137,8 @@ def add_text(history, task_history, text):
|
|
132 |
return history, task_history
|
133 |
|
134 |
def add_file(history, task_history, file):
|
|
|
|
|
135 |
print("Add File - Before: task_history =", task_history)
|
136 |
history.append(((file.name,), None))
|
137 |
task_history.append(((file.name,), None))
|
@@ -139,6 +146,8 @@ def add_file(history, task_history, file):
|
|
139 |
return history, task_history
|
140 |
|
141 |
def add_mic(history, task_history, file):
|
|
|
|
|
142 |
print("Add Mic - Before: task_history =", task_history)
|
143 |
if file is None:
|
144 |
return history, task_history
|
@@ -153,6 +162,8 @@ def reset_user_input():
|
|
153 |
return gr.update(value="")
|
154 |
|
155 |
def reset_state(task_history):
|
|
|
|
|
156 |
print("Reset State - Before: task_history =", task_history)
|
157 |
task_history = []
|
158 |
print("Reset State - After: task_history =", task_history)
|
@@ -163,11 +174,11 @@ iface = gr.Interface(
|
|
163 |
inputs=[
|
164 |
gr.Audio(label="Audio Input"),
|
165 |
gr.Textbox(label="Text Query"),
|
166 |
-
gr.State(
|
167 |
],
|
168 |
outputs=[
|
169 |
"text",
|
170 |
-
gr.State()
|
171 |
],
|
172 |
title="Audio-Text Interaction Model",
|
173 |
description="This model can process an audio input along with a text query and provide a response.",
|
|
|
8 |
from pathlib import Path
|
9 |
from pydub import AudioSegment
|
10 |
|
|
|
11 |
torch.manual_seed(420)
|
12 |
tokenizer = AutoTokenizer.from_pretrained("Qwen/Qwen-Audio-Chat", trust_remote_code=True)
|
13 |
model = AutoModelForCausalLM.from_pretrained("Qwen/Qwen-Audio-Chat", device_map="cuda", trust_remote_code=True).eval()
|
|
|
44 |
return text
|
45 |
|
46 |
def predict(_chatbot, task_history, user_input):
|
47 |
+
if task_history is None or not isinstance(task_history, list):
|
48 |
+
task_history = []
|
49 |
print("Predict - Start: task_history =", task_history)
|
50 |
if not isinstance(task_history, list) or not all(isinstance(item, tuple) and len(item) == 2 for item in task_history):
|
51 |
print("Error: task_history should be a list of tuples of length 2.")
|
|
|
108 |
|
109 |
|
110 |
def regenerate(_chatbot, task_history):
|
111 |
+
if task_history is None or not isinstance(task_history, list):
|
112 |
+
task_history = []
|
113 |
print("Regenerate - Start: task_history =", task_history)
|
114 |
if not task_history:
|
115 |
return _chatbot
|
|
|
126 |
return predict(_chatbot, task_history)
|
127 |
|
128 |
def add_text(history, task_history, text):
|
129 |
+
if task_history is None or not isinstance(task_history, list):
|
130 |
+
task_history = []
|
131 |
print("Add Text - Before: task_history =", task_history)
|
132 |
if not isinstance(task_history, list):
|
133 |
task_history = []
|
|
|
137 |
return history, task_history
|
138 |
|
139 |
def add_file(history, task_history, file):
|
140 |
+
if task_history is None or not isinstance(task_history, list):
|
141 |
+
task_history = []
|
142 |
print("Add File - Before: task_history =", task_history)
|
143 |
history.append(((file.name,), None))
|
144 |
task_history.append(((file.name,), None))
|
|
|
146 |
return history, task_history
|
147 |
|
148 |
def add_mic(history, task_history, file):
|
149 |
+
if task_history is None or not isinstance(task_history, list):
|
150 |
+
task_history = []
|
151 |
print("Add Mic - Before: task_history =", task_history)
|
152 |
if file is None:
|
153 |
return history, task_history
|
|
|
162 |
return gr.update(value="")
|
163 |
|
164 |
def reset_state(task_history):
|
165 |
+
if task_history is None or not isinstance(task_history, list):
|
166 |
+
task_history = []
|
167 |
print("Reset State - Before: task_history =", task_history)
|
168 |
task_history = []
|
169 |
print("Reset State - After: task_history =", task_history)
|
|
|
174 |
inputs=[
|
175 |
gr.Audio(label="Audio Input"),
|
176 |
gr.Textbox(label="Text Query"),
|
177 |
+
gr.State()
|
178 |
],
|
179 |
outputs=[
|
180 |
"text",
|
181 |
+
gr.State()
|
182 |
],
|
183 |
title="Audio-Text Interaction Model",
|
184 |
description="This model can process an audio input along with a text query and provide a response.",
|