awacke1 commited on
Commit
968c855
1 Parent(s): b1d6785

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +41 -4
app.py CHANGED
@@ -1854,6 +1854,35 @@ def transcribe_canary(filename):
1854
  st.write(result)
1855
  return result
1856
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1857
  def transcribe_whisperLTurbo(filename):
1858
  client = Client("hf-audio/whisper-large-v3-turbo")
1859
  result = client.predict(
@@ -1865,12 +1894,20 @@ def transcribe_whisperLTurbo(filename):
1865
  return result
1866
 
1867
  # Transcript to arxiv and client chat completion ------------------------- !!
1868
- filename = save_and_play_audio(audio_recorder)
1869
- if filename is not None:
1870
- transcript=''
 
 
 
 
 
 
 
 
1871
  #transcript=transcribe_whisperLTurbo(filename)
1872
  #transcript=transcribe_canary(filename)
1873
- transcript=process_audio(filename)
1874
 
1875
  # Search ArXiV and get the Summary and Reference Papers Listing
1876
  result = search_arxiv(transcript)
 
1854
  st.write(result)
1855
  return result
1856
 
1857
+
1858
+ def transcribe_audio(file_path, model):
1859
+ key = os.getenv('OPENAI_API_KEY')
1860
+ headers = {
1861
+ "Authorization": f"Bearer {key}",
1862
+ }
1863
+ with open(file_path, 'rb') as f:
1864
+ data = {'file': f}
1865
+ st.write("Read file {file_path}", file_path)
1866
+ OPENAI_API_URL = "https://api.openai.com/v1/audio/transcriptions"
1867
+ response = requests.post(OPENAI_API_URL, headers=headers, files=data, data={'model': model})
1868
+ if response.status_code == 200:
1869
+ st.write(response.json())
1870
+ chatResponse = chat_with_model(response.json().get('text'), '') # *************************************
1871
+ transcript = response.json().get('text')
1872
+ #st.write('Responses:')
1873
+ #st.write(chatResponse)
1874
+ filename = generate_filename(transcript, 'txt')
1875
+ #create_file(filename, transcript, chatResponse)
1876
+ response = chatResponse
1877
+ user_prompt = transcript
1878
+ create_file(filename, user_prompt, response, should_save)
1879
+ return transcript
1880
+ else:
1881
+ st.write(response.json())
1882
+ st.error("Error in API call.")
1883
+ return None
1884
+
1885
+
1886
  def transcribe_whisperLTurbo(filename):
1887
  client = Client("hf-audio/whisper-large-v3-turbo")
1888
  result = client.predict(
 
1894
  return result
1895
 
1896
  # Transcript to arxiv and client chat completion ------------------------- !!
1897
+ filename = save_and_play_audio(audio_recorder
1898
+ if filename is not None: # whisper1
1899
+ try:
1900
+ transcript = transcribe_audio(filename, "whisper-1")
1901
+ except:
1902
+ st.write(' ')
1903
+ st.sidebar.markdown(get_table_download_link(filename), unsafe_allow_html=True)
1904
+ filename = None
1905
+
1906
+ #if filename is not None:
1907
+ # transcript=''
1908
  #transcript=transcribe_whisperLTurbo(filename)
1909
  #transcript=transcribe_canary(filename)
1910
+ # transcript=process_audio(filename)
1911
 
1912
  # Search ArXiV and get the Summary and Reference Papers Listing
1913
  result = search_arxiv(transcript)