Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,81 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
import edge_tts
|
3 |
+
import asyncio
|
4 |
+
import tempfile
|
5 |
+
import os
|
6 |
+
from huggingface_hub import InferenceClient
|
7 |
+
import re
|
8 |
+
from streaming_stt_nemo import Model
|
9 |
+
import torch
|
10 |
+
import random
|
11 |
+
import pandas as pd
|
12 |
+
from datetime import datetime
|
13 |
+
import base64
|
14 |
+
import io
|
15 |
+
|
16 |
+
# ... (previous imports and functions remain the same)
|
17 |
+
|
18 |
+
def download_history():
|
19 |
+
csv_buffer = io.StringIO()
|
20 |
+
history_df.to_csv(csv_buffer, index=False)
|
21 |
+
csv_string = csv_buffer.getvalue()
|
22 |
+
b64 = base64.b64encode(csv_string.encode()).decode()
|
23 |
+
href = f'data:text/csv;base64,{b64}'
|
24 |
+
return href
|
25 |
+
|
26 |
+
DESCRIPTION = """ # <center><b>JARVIS⚡</b></center>
|
27 |
+
### <center>A personal Assistant of Tony Stark for YOU
|
28 |
+
### <center>Voice Chat with your personal Assistant</center>
|
29 |
+
"""
|
30 |
+
|
31 |
+
with gr.Blocks(css="style.css") as demo:
|
32 |
+
gr.Markdown(DESCRIPTION)
|
33 |
+
with gr.Row():
|
34 |
+
select = gr.Dropdown([
|
35 |
+
'Mixtral 8x7B',
|
36 |
+
'Llama 3 8B',
|
37 |
+
'Mistral 7B v0.3',
|
38 |
+
'Phi 3 mini',
|
39 |
+
],
|
40 |
+
value="Mistral 7B v0.3",
|
41 |
+
label="Model"
|
42 |
+
)
|
43 |
+
seed = gr.Slider(
|
44 |
+
label="Seed",
|
45 |
+
minimum=0,
|
46 |
+
maximum=999999,
|
47 |
+
step=1,
|
48 |
+
value=0,
|
49 |
+
visible=False
|
50 |
+
)
|
51 |
+
|
52 |
+
input_audio = gr.Audio(label="User", sources="microphone", type="filepath")
|
53 |
+
output_audio = gr.Audio(label="AI", type="filepath", autoplay=True)
|
54 |
+
|
55 |
+
# Add a DataFrame to display the history
|
56 |
+
history_display = gr.DataFrame(label="Query History")
|
57 |
+
|
58 |
+
# Add a download button for the history
|
59 |
+
download_button = gr.Button("Download History")
|
60 |
+
download_link = gr.HTML()
|
61 |
+
|
62 |
+
demo.load(fn=lambda: gr.update(visible=True), outputs=[download_button])
|
63 |
+
|
64 |
+
def process_audio(audio, model, seed):
|
65 |
+
response = asyncio.run(respond(audio, model, seed))
|
66 |
+
return next(response)
|
67 |
+
|
68 |
+
input_audio.change(
|
69 |
+
fn=process_audio,
|
70 |
+
inputs=[input_audio, select, seed],
|
71 |
+
outputs=[output_audio]
|
72 |
+
)
|
73 |
+
|
74 |
+
# Update the history display after each interaction
|
75 |
+
output_audio.change(fn=display_history, outputs=[history_display])
|
76 |
+
|
77 |
+
# Connect the download button to the download function
|
78 |
+
download_button.click(fn=download_history, outputs=[download_link])
|
79 |
+
|
80 |
+
if __name__ == "__main__":
|
81 |
+
demo.queue(max_size=200).launch(share=True)
|