Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -11,40 +11,7 @@ import random
|
|
11 |
import pandas as pd
|
12 |
from datetime import datetime
|
13 |
|
14 |
-
|
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'])
|
@@ -71,7 +38,7 @@ def models(text, model="Mixtral 8x7B", seed=42):
|
|
71 |
|
72 |
# Add the current interaction to the history DataFrame
|
73 |
new_row = pd.DataFrame({
|
74 |
-
'Timestamp': [datetime.now()],
|
75 |
'Request': [text],
|
76 |
'Response': [output]
|
77 |
})
|
@@ -94,54 +61,7 @@ def display_history():
|
|
94 |
def download_history():
|
95 |
return history_df.to_csv(index=False)
|
96 |
|
97 |
-
|
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([ 'Mixtral 8x7B',
|
106 |
-
'Llama 3 8B',
|
107 |
-
'Mistral 7B v0.3',
|
108 |
-
'Phi 3 mini',
|
109 |
-
],
|
110 |
-
value="Mistral 7B v0.3",
|
111 |
-
label="Model"
|
112 |
-
)
|
113 |
-
seed = gr.Slider(
|
114 |
-
label="Seed",
|
115 |
-
minimum=0,
|
116 |
-
maximum=999999,
|
117 |
-
step=1,
|
118 |
-
value=0,
|
119 |
-
visible=False
|
120 |
-
)
|
121 |
-
input = gr.Audio(label="User", sources="microphone", type="filepath", waveform_options=False)
|
122 |
-
output = gr.Audio(label="AI", type="filepath",
|
123 |
-
interactive=False,
|
124 |
-
autoplay=True,
|
125 |
-
elem_classes="audio")
|
126 |
-
|
127 |
-
# Add a DataFrame to display the history
|
128 |
-
history_display = gr.DataFrame(label="Query History")
|
129 |
-
|
130 |
-
# Add a download button for the history
|
131 |
-
download_button = gr.Button("Download History")
|
132 |
-
|
133 |
-
gr.Interface(
|
134 |
-
batch=True,
|
135 |
-
max_batch_size=10,
|
136 |
-
fn=respond,
|
137 |
-
inputs=[input, select, seed],
|
138 |
-
outputs=[output], live=True)
|
139 |
-
|
140 |
-
# Update the history display after each interaction
|
141 |
-
output.change(fn=display_history, outputs=[history_display])
|
142 |
-
|
143 |
-
# Connect the download button to the download function
|
144 |
-
download_button.click(fn=download_history, outputs=[gr.File(label="Download CSV")])
|
145 |
|
146 |
if __name__ == "__main__":
|
147 |
-
demo.queue(max_size=200).launch()
|
|
|
11 |
import pandas as pd
|
12 |
from datetime import datetime
|
13 |
|
14 |
+
# ... (previous code remains the same)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
15 |
|
16 |
# Initialize an empty DataFrame to store the history
|
17 |
history_df = pd.DataFrame(columns=['Timestamp', 'Request', 'Response'])
|
|
|
38 |
|
39 |
# Add the current interaction to the history DataFrame
|
40 |
new_row = pd.DataFrame({
|
41 |
+
'Timestamp': [datetime.now().strftime("%Y-%m-%d %H:%M:%S")], # Convert to string
|
42 |
'Request': [text],
|
43 |
'Response': [output]
|
44 |
})
|
|
|
61 |
def download_history():
|
62 |
return history_df.to_csv(index=False)
|
63 |
|
64 |
+
# ... (rest of the code remains the same)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
65 |
|
66 |
if __name__ == "__main__":
|
67 |
+
demo.queue(max_size=200).launch(share=True) # Added share=True for public link
|