Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -12,7 +12,6 @@ import pandas as pd
|
|
12 |
from datetime import datetime
|
13 |
import base64
|
14 |
import io
|
15 |
-
import json
|
16 |
|
17 |
default_lang = "en"
|
18 |
engines = { default_lang: Model(default_lang) }
|
@@ -52,17 +51,6 @@ Respond in a normal, conversational manner while being friendly and helpful.
|
|
52 |
# Initialize an empty DataFrame to store the history
|
53 |
history_df = pd.DataFrame(columns=['Timestamp', 'Request', 'Response'])
|
54 |
|
55 |
-
def save_history():
|
56 |
-
history_df.to_json('chat_history.json', orient='records')
|
57 |
-
|
58 |
-
def load_history():
|
59 |
-
global history_df
|
60 |
-
try:
|
61 |
-
history_df = pd.read_json('chat_history.json', orient='records')
|
62 |
-
except FileNotFoundError:
|
63 |
-
history_df = pd.DataFrame(columns=['Timestamp', 'Request', 'Response'])
|
64 |
-
return history_df
|
65 |
-
|
66 |
def models(text, model="Mixtral 8x7B", seed=42):
|
67 |
global history_df
|
68 |
|
@@ -90,7 +78,6 @@ def models(text, model="Mixtral 8x7B", seed=42):
|
|
90 |
'Response': [output]
|
91 |
})
|
92 |
history_df = pd.concat([history_df, new_row], ignore_index=True)
|
93 |
-
save_history()
|
94 |
|
95 |
return output
|
96 |
|
@@ -104,7 +91,7 @@ async def respond(audio, model, seed):
|
|
104 |
return tmp_path
|
105 |
|
106 |
def display_history():
|
107 |
-
return
|
108 |
|
109 |
def download_history():
|
110 |
csv_buffer = io.StringIO()
|
@@ -152,19 +139,19 @@ with gr.Blocks(css="style.css") as demo:
|
|
152 |
|
153 |
def process_audio(audio, model, seed):
|
154 |
response = asyncio.run(respond(audio, model, seed))
|
155 |
-
return response
|
156 |
|
157 |
input_audio.change(
|
158 |
fn=process_audio,
|
159 |
inputs=[input_audio, select, seed],
|
160 |
-
outputs=[output_audio
|
161 |
)
|
162 |
|
|
|
|
|
|
|
163 |
# Connect the download button to the download function
|
164 |
download_button.click(fn=download_history, outputs=[download_link])
|
165 |
|
166 |
-
# Load history when the page is refreshed
|
167 |
-
demo.load(fn=display_history, outputs=[history_display])
|
168 |
-
|
169 |
if __name__ == "__main__":
|
170 |
-
demo.queue(max_size=200).launch()
|
|
|
12 |
from datetime import datetime
|
13 |
import base64
|
14 |
import io
|
|
|
15 |
|
16 |
default_lang = "en"
|
17 |
engines = { default_lang: Model(default_lang) }
|
|
|
51 |
# Initialize an empty DataFrame to store the history
|
52 |
history_df = pd.DataFrame(columns=['Timestamp', 'Request', 'Response'])
|
53 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
54 |
def models(text, model="Mixtral 8x7B", seed=42):
|
55 |
global history_df
|
56 |
|
|
|
78 |
'Response': [output]
|
79 |
})
|
80 |
history_df = pd.concat([history_df, new_row], ignore_index=True)
|
|
|
81 |
|
82 |
return output
|
83 |
|
|
|
91 |
return tmp_path
|
92 |
|
93 |
def display_history():
|
94 |
+
return history_df
|
95 |
|
96 |
def download_history():
|
97 |
csv_buffer = io.StringIO()
|
|
|
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)
|