Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -14,7 +14,6 @@ import base64
|
|
14 |
import io
|
15 |
import json
|
16 |
|
17 |
-
# 🌍 Language setup
|
18 |
default_lang = "en"
|
19 |
engines = { default_lang: Model(default_lang) }
|
20 |
|
@@ -50,7 +49,7 @@ Respond in a manner that reflects your expertise and wisdom.
|
|
50 |
[USER]
|
51 |
"""
|
52 |
|
53 |
-
#
|
54 |
history_df = pd.DataFrame(columns=['Timestamp', 'Model', 'Input Size', 'Output Size', 'Request', 'Response'])
|
55 |
|
56 |
def save_history():
|
@@ -87,7 +86,7 @@ def models(text, model="Llama 3 8B", seed=42):
|
|
87 |
if not response.token.text == "</s>":
|
88 |
output += response.token.text
|
89 |
|
90 |
-
#
|
91 |
new_row = pd.DataFrame({
|
92 |
'Timestamp': [datetime.now()],
|
93 |
'Model': [model],
|
@@ -101,7 +100,7 @@ def models(text, model="Llama 3 8B", seed=42):
|
|
101 |
|
102 |
return output
|
103 |
|
104 |
-
#
|
105 |
VOICES = [
|
106 |
"en-US-AriaNeural",
|
107 |
"en-US-GuyNeural",
|
@@ -136,7 +135,6 @@ def download_history():
|
|
136 |
|
137 |
DESCRIPTION = """# <center>Dr. Nova Quantum⚡ - Your Personal Guide to the Frontiers of Science and Technology</center>"""
|
138 |
|
139 |
-
# 🎨 Gradio interface
|
140 |
with gr.Blocks(css="style.css") as demo:
|
141 |
gr.Markdown(DESCRIPTION)
|
142 |
with gr.Row():
|
@@ -163,9 +161,6 @@ with gr.Blocks(css="style.css") as demo:
|
|
163 |
label="Dr. Nova Quantum's Voice"
|
164 |
)
|
165 |
|
166 |
-
# 🔄 New Chat button
|
167 |
-
new_chat_button = gr.Button("🔄 New Chat", variant="primary")
|
168 |
-
|
169 |
input_audio = gr.Audio(label="User", sources="microphone", type="filepath")
|
170 |
output_audio = gr.Audio(label="Dr. Nova Quantum", type="filepath", autoplay=True)
|
171 |
|
@@ -182,26 +177,16 @@ with gr.Blocks(css="style.css") as demo:
|
|
182 |
text = transcribe(audio)
|
183 |
return response, display_history(), text, models(text, model, seed)
|
184 |
|
185 |
-
# 🧹 Reset function for New Chat
|
186 |
-
def reset_interface():
|
187 |
-
return None, None, "", ""
|
188 |
-
|
189 |
input_audio.change(
|
190 |
fn=process_audio,
|
191 |
inputs=[input_audio, select, seed, voice_select],
|
192 |
outputs=[output_audio, history_display, request_md, response_md]
|
193 |
)
|
194 |
|
195 |
-
new_chat_button.click(
|
196 |
-
fn=reset_interface,
|
197 |
-
outputs=[input_audio, output_audio, request_md, response_md]
|
198 |
-
)
|
199 |
-
|
200 |
download_button.click(fn=download_history, outputs=[download_link])
|
201 |
|
202 |
demo.load(fn=display_history, outputs=[history_display])
|
203 |
|
204 |
-
# 🚀 Launch the app
|
205 |
if __name__ == "__main__":
|
206 |
load_history()
|
207 |
demo.queue(max_size=200).launch()
|
|
|
14 |
import io
|
15 |
import json
|
16 |
|
|
|
17 |
default_lang = "en"
|
18 |
engines = { default_lang: Model(default_lang) }
|
19 |
|
|
|
49 |
[USER]
|
50 |
"""
|
51 |
|
52 |
+
# Initialize an empty DataFrame to store the history
|
53 |
history_df = pd.DataFrame(columns=['Timestamp', 'Model', 'Input Size', 'Output Size', 'Request', 'Response'])
|
54 |
|
55 |
def save_history():
|
|
|
86 |
if not response.token.text == "</s>":
|
87 |
output += response.token.text
|
88 |
|
89 |
+
# Add the current interaction to the history DataFrame
|
90 |
new_row = pd.DataFrame({
|
91 |
'Timestamp': [datetime.now()],
|
92 |
'Model': [model],
|
|
|
100 |
|
101 |
return output
|
102 |
|
103 |
+
# Add a list of available voices
|
104 |
VOICES = [
|
105 |
"en-US-AriaNeural",
|
106 |
"en-US-GuyNeural",
|
|
|
135 |
|
136 |
DESCRIPTION = """# <center>Dr. Nova Quantum⚡ - Your Personal Guide to the Frontiers of Science and Technology</center>"""
|
137 |
|
|
|
138 |
with gr.Blocks(css="style.css") as demo:
|
139 |
gr.Markdown(DESCRIPTION)
|
140 |
with gr.Row():
|
|
|
161 |
label="Dr. Nova Quantum's Voice"
|
162 |
)
|
163 |
|
|
|
|
|
|
|
164 |
input_audio = gr.Audio(label="User", sources="microphone", type="filepath")
|
165 |
output_audio = gr.Audio(label="Dr. Nova Quantum", type="filepath", autoplay=True)
|
166 |
|
|
|
177 |
text = transcribe(audio)
|
178 |
return response, display_history(), text, models(text, model, seed)
|
179 |
|
|
|
|
|
|
|
|
|
180 |
input_audio.change(
|
181 |
fn=process_audio,
|
182 |
inputs=[input_audio, select, seed, voice_select],
|
183 |
outputs=[output_audio, history_display, request_md, response_md]
|
184 |
)
|
185 |
|
|
|
|
|
|
|
|
|
|
|
186 |
download_button.click(fn=download_history, outputs=[download_link])
|
187 |
|
188 |
demo.load(fn=display_history, outputs=[history_display])
|
189 |
|
|
|
190 |
if __name__ == "__main__":
|
191 |
load_history()
|
192 |
demo.queue(max_size=200).launch()
|