not-lain commited on
Commit
d22abe6
1 Parent(s): f0b4737

return of the king

Browse files
Files changed (1) hide show
  1. app.py +18 -18
app.py CHANGED
@@ -10,7 +10,7 @@ import json
10
  import dotenv
11
  from scipy.io.wavfile import write
12
  import PIL
13
- # from openai import OpenAI
14
  dotenv.load_dotenv()
15
 
16
  seamless_client = Client("facebook/seamless_m4t")
@@ -22,15 +22,15 @@ def process_speech(audio):
22
  """
23
  processing sound using seamless_m4t
24
  """
25
- audio_name = f"{np.random.randint(0, 100)}.wav"
26
- sr, data = audio
27
- write(audio_name, sr, data.astype(np.int16))
28
 
29
  out = seamless_client.predict(
30
  "S2TT",
31
  "file",
32
  None,
33
- audio_name,
34
  "",
35
  "French",# source language
36
  "English",# target language
@@ -236,18 +236,18 @@ def process_and_query(text=None):
236
  # Now, use the text (either provided by the user or obtained from OpenAI) to query Vectara
237
  vectara_response_json = query_vectara(text)
238
  markdown_output = convert_to_markdown(vectara_response_json)
239
- # client = OpenAI()
240
- # prompt ="Answer in the same language, write it better, more understandable and shorter:"
241
- # markdown_output_final = markdown_output
242
-
243
- # completion = client.chat.completions.create(
244
- # model="gpt-3.5-turbo",
245
- # messages=[
246
- # {"role": "system", "content": prompt},
247
- # {"role": "user", "content": markdown_output_final}
248
- # ]
249
- # )
250
- # final_response= completion.choices[0].message.content
251
  return markdown_output
252
  except Exception as e:
253
  return str(e)
@@ -305,7 +305,7 @@ with gr.Blocks(theme='ParityError/Anime') as iface :
305
  image_button = gr.Button("process image")
306
  with gr.Tab("speech to text translation"):
307
  audio_input = gr.Audio(label="talk in french",
308
- sources=["microphone"],type="numpy")
309
  audio_output = gr.Markdown(label="output text")
310
  audio_button = gr.Button("process audio")
311
  text_button.click(process_and_query, inputs=text_input, outputs=text_output)
 
10
  import dotenv
11
  from scipy.io.wavfile import write
12
  import PIL
13
+ from openai import OpenAI
14
  dotenv.load_dotenv()
15
 
16
  seamless_client = Client("facebook/seamless_m4t")
 
22
  """
23
  processing sound using seamless_m4t
24
  """
25
+ # audio_name = f"{np.random.randint(0, 100)}.wav"
26
+ # sr, data = audio
27
+ # write(audio_name, sr, data.astype(np.int16))
28
 
29
  out = seamless_client.predict(
30
  "S2TT",
31
  "file",
32
  None,
33
+ audio, #audio_name
34
  "",
35
  "French",# source language
36
  "English",# target language
 
236
  # Now, use the text (either provided by the user or obtained from OpenAI) to query Vectara
237
  vectara_response_json = query_vectara(text)
238
  markdown_output = convert_to_markdown(vectara_response_json)
239
+ client = OpenAI()
240
+ prompt ="Answer in the same language, write it better, more understandable and shorter:"
241
+ markdown_output_final = markdown_output
242
+
243
+ completion = client.chat.completions.create(
244
+ model="gpt-3.5-turbo",
245
+ messages=[
246
+ {"role": "system", "content": prompt},
247
+ {"role": "user", "content": markdown_output_final}
248
+ ]
249
+ )
250
+ final_response= completion.choices[0].message.content
251
  return markdown_output
252
  except Exception as e:
253
  return str(e)
 
305
  image_button = gr.Button("process image")
306
  with gr.Tab("speech to text translation"):
307
  audio_input = gr.Audio(label="talk in french",
308
+ sources=["microphone"],type="filepath",)
309
  audio_output = gr.Markdown(label="output text")
310
  audio_button = gr.Button("process audio")
311
  text_button.click(process_and_query, inputs=text_input, outputs=text_output)