Update app.py
Browse files
app.py
CHANGED
@@ -10,6 +10,8 @@ import torch
|
|
10 |
import random
|
11 |
import pandas as pd
|
12 |
from datetime import datetime
|
|
|
|
|
13 |
|
14 |
default_lang = "en"
|
15 |
engines = { default_lang: Model(default_lang) }
|
@@ -86,13 +88,18 @@ async def respond(audio, model, seed):
|
|
86 |
with tempfile.NamedTemporaryFile(delete=False, suffix=".wav") as tmp_file:
|
87 |
tmp_path = tmp_file.name
|
88 |
await communicate.save(tmp_path)
|
89 |
-
|
90 |
|
91 |
def display_history():
|
92 |
return history_df
|
93 |
|
94 |
def download_history():
|
95 |
-
|
|
|
|
|
|
|
|
|
|
|
96 |
|
97 |
DESCRIPTION = """ # <center><b>JARVIS⚡</b></center>
|
98 |
### <center>A personal Assistant of Tony Stark for YOU
|
@@ -119,32 +126,32 @@ with gr.Blocks(css="style.css") as demo:
|
|
119 |
value=0,
|
120 |
visible=False
|
121 |
)
|
122 |
-
|
123 |
-
|
124 |
-
|
125 |
-
autoplay=True,
|
126 |
-
elem_classes="audio")
|
127 |
|
128 |
# Add a DataFrame to display the history
|
129 |
history_display = gr.DataFrame(label="Query History")
|
130 |
|
131 |
# Add a download button for the history
|
132 |
download_button = gr.Button("Download History")
|
|
|
133 |
|
134 |
-
|
135 |
-
|
136 |
-
|
137 |
-
|
138 |
-
|
139 |
-
|
140 |
-
|
|
|
141 |
)
|
142 |
|
143 |
# Update the history display after each interaction
|
144 |
-
|
145 |
|
146 |
# Connect the download button to the download function
|
147 |
-
download_button.click(fn=download_history, outputs=[
|
148 |
|
149 |
if __name__ == "__main__":
|
150 |
-
demo.queue(max_size=200).launch(share=True)
|
|
|
10 |
import random
|
11 |
import pandas as pd
|
12 |
from datetime import datetime
|
13 |
+
import base64
|
14 |
+
import io
|
15 |
|
16 |
default_lang = "en"
|
17 |
engines = { default_lang: Model(default_lang) }
|
|
|
88 |
with tempfile.NamedTemporaryFile(delete=False, suffix=".wav") as tmp_file:
|
89 |
tmp_path = tmp_file.name
|
90 |
await communicate.save(tmp_path)
|
91 |
+
return tmp_path
|
92 |
|
93 |
def display_history():
|
94 |
return history_df
|
95 |
|
96 |
def download_history():
|
97 |
+
csv_buffer = io.StringIO()
|
98 |
+
history_df.to_csv(csv_buffer, index=False)
|
99 |
+
csv_string = csv_buffer.getvalue()
|
100 |
+
b64 = base64.b64encode(csv_string.encode()).decode()
|
101 |
+
href = f'data:text/csv;base64,{b64}'
|
102 |
+
return gr.HTML(f'<a href="{href}" download="chat_history.csv">Download Chat History</a>')
|
103 |
|
104 |
DESCRIPTION = """ # <center><b>JARVIS⚡</b></center>
|
105 |
### <center>A personal Assistant of Tony Stark for YOU
|
|
|
126 |
value=0,
|
127 |
visible=False
|
128 |
)
|
129 |
+
|
130 |
+
input_audio = gr.Audio(label="User", sources="microphone", type="filepath")
|
131 |
+
output_audio = gr.Audio(label="AI", type="filepath", autoplay=True)
|
|
|
|
|
132 |
|
133 |
# Add a DataFrame to display the history
|
134 |
history_display = gr.DataFrame(label="Query History")
|
135 |
|
136 |
# Add a download button for the history
|
137 |
download_button = gr.Button("Download History")
|
138 |
+
download_link = gr.HTML()
|
139 |
|
140 |
+
def process_audio(audio, model, seed):
|
141 |
+
response = asyncio.run(respond(audio, model, seed))
|
142 |
+
return response
|
143 |
+
|
144 |
+
input_audio.change(
|
145 |
+
fn=process_audio,
|
146 |
+
inputs=[input_audio, select, seed],
|
147 |
+
outputs=[output_audio]
|
148 |
)
|
149 |
|
150 |
# Update the history display after each interaction
|
151 |
+
output_audio.change(fn=display_history, outputs=[history_display])
|
152 |
|
153 |
# Connect the download button to the download function
|
154 |
+
download_button.click(fn=download_history, outputs=[download_link])
|
155 |
|
156 |
if __name__ == "__main__":
|
157 |
+
demo.queue(max_size=200).launch(share=True)
|