Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -11,7 +11,40 @@ import random
|
|
11 |
import pandas as pd
|
12 |
from datetime import datetime
|
13 |
|
14 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
15 |
|
16 |
# Initialize an empty DataFrame to store the history
|
17 |
history_df = pd.DataFrame(columns=['Timestamp', 'Request', 'Response'])
|
@@ -61,7 +94,57 @@ def display_history():
|
|
61 |
def download_history():
|
62 |
return history_df.to_csv(index=False)
|
63 |
|
64 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
65 |
|
66 |
if __name__ == "__main__":
|
67 |
demo.queue(max_size=200).launch(share=True) # Added share=True for public link
|
|
|
11 |
import pandas as pd
|
12 |
from datetime import datetime
|
13 |
|
14 |
+
default_lang = "en"
|
15 |
+
engines = { default_lang: Model(default_lang) }
|
16 |
+
|
17 |
+
def transcribe(audio):
|
18 |
+
lang = "en"
|
19 |
+
model = engines[lang]
|
20 |
+
text = model.stt_file(audio)[0]
|
21 |
+
return text
|
22 |
+
|
23 |
+
HF_TOKEN = os.environ.get("HF_TOKEN", None)
|
24 |
+
|
25 |
+
def client_fn(model):
|
26 |
+
if "Mixtral" in model:
|
27 |
+
return InferenceClient("mistralai/Mixtral-8x7B-Instruct-v0.1")
|
28 |
+
elif "Llama" in model:
|
29 |
+
return InferenceClient("meta-llama/Meta-Llama-3-8B-Instruct")
|
30 |
+
elif "Mistral" in model:
|
31 |
+
return InferenceClient("mistralai/Mistral-7B-Instruct-v0.2")
|
32 |
+
elif "Phi" in model:
|
33 |
+
return InferenceClient("microsoft/Phi-3-mini-4k-instruct")
|
34 |
+
else:
|
35 |
+
return InferenceClient("microsoft/Phi-3-mini-4k-instruct")
|
36 |
+
|
37 |
+
def randomize_seed_fn(seed: int) -> int:
|
38 |
+
seed = random.randint(0, 999999)
|
39 |
+
return seed
|
40 |
+
|
41 |
+
system_instructions1 = """
|
42 |
+
[SYSTEM] Answer as Real Jarvis JARVIS, Made by 'Tony Stark.'
|
43 |
+
Keep conversation friendly, short, clear, and concise.
|
44 |
+
Avoid unnecessary introductions and answer the user's questions directly.
|
45 |
+
Respond in a normal, conversational manner while being friendly and helpful.
|
46 |
+
[USER]
|
47 |
+
"""
|
48 |
|
49 |
# Initialize an empty DataFrame to store the history
|
50 |
history_df = pd.DataFrame(columns=['Timestamp', 'Request', 'Response'])
|
|
|
94 |
def download_history():
|
95 |
return history_df.to_csv(index=False)
|
96 |
|
97 |
+
DESCRIPTION = """ # <center><b>JARVIS⚡</b></center>
|
98 |
+
### <center>A personal Assistant of Tony Stark for YOU
|
99 |
+
### <center>Voice Chat with your personal Assistant</center>
|
100 |
+
"""
|
101 |
+
|
102 |
+
with gr.Blocks(css="style.css") as demo:
|
103 |
+
gr.Markdown(DESCRIPTION)
|
104 |
+
with gr.Row():
|
105 |
+
select = gr.Dropdown([
|
106 |
+
'Mixtral 8x7B',
|
107 |
+
'Llama 3 8B',
|
108 |
+
'Mistral 7B v0.3',
|
109 |
+
'Phi 3 mini',
|
110 |
+
],
|
111 |
+
value="Mistral 7B v0.3",
|
112 |
+
label="Model"
|
113 |
+
)
|
114 |
+
seed = gr.Slider(
|
115 |
+
label="Seed",
|
116 |
+
minimum=0,
|
117 |
+
maximum=999999,
|
118 |
+
step=1,
|
119 |
+
value=0,
|
120 |
+
visible=False
|
121 |
+
)
|
122 |
+
input = gr.Audio(label="User", sources="microphone", type="filepath", waveform_options=False)
|
123 |
+
output = gr.Audio(label="AI", type="filepath",
|
124 |
+
interactive=False,
|
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 |
+
gr.Interface(
|
135 |
+
batch=True,
|
136 |
+
max_batch_size=10,
|
137 |
+
fn=respond,
|
138 |
+
inputs=[input, select, seed],
|
139 |
+
outputs=[output],
|
140 |
+
live=True
|
141 |
+
)
|
142 |
+
|
143 |
+
# Update the history display after each interaction
|
144 |
+
output.change(fn=display_history, outputs=[history_display])
|
145 |
+
|
146 |
+
# Connect the download button to the download function
|
147 |
+
download_button.click(fn=download_history, outputs=[gr.File(label="Download CSV")])
|
148 |
|
149 |
if __name__ == "__main__":
|
150 |
demo.queue(max_size=200).launch(share=True) # Added share=True for public link
|