awacke1 commited on
Commit
16d72b2
·
verified ·
1 Parent(s): ce8c4ac

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +24 -17
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
- yield tmp_path
90
 
91
  def display_history():
92
  return history_df
93
 
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
@@ -119,32 +126,32 @@ with gr.Blocks(css="style.css") as demo:
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
 
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)