Shreyas094 commited on
Commit
760747b
·
verified ·
1 Parent(s): cead1c3

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +28 -12
app.py CHANGED
@@ -28,7 +28,7 @@ llama_cloud_api_key = os.environ.get("LLAMA_CLOUD_API_KEY")
28
  ACCOUNT_ID = os.environ.get("CLOUDFARE_ACCOUNT_ID")
29
  API_TOKEN = os.environ.get("CLOUDFLARE_AUTH_TOKEN")
30
  API_BASE_URL = "https://api.cloudflare.com/client/v4/accounts/a17f03e0f049ccae0c15cdcf3b9737ce/ai/run/"
31
- whisper_api = InferenceClient("openai/whisper-small", token=huggingface_token)
32
 
33
  print(f"ACCOUNT_ID: {ACCOUNT_ID}")
34
  print(f"CLOUDFLARE_AUTH_TOKEN: {API_TOKEN[:5]}..." if API_TOKEN else "Not set")
@@ -616,26 +616,42 @@ Write a detailed and complete response that answers the following user question:
616
  logging.info("Finished generating response")
617
 
618
  def transcribe(audio_file):
 
619
  if audio_file is None:
620
- return ""
621
-
622
- with open(audio_file, "rb") as f:
623
- audio_data = f.read()
624
-
625
- # Create a file-like object from the audio data
626
- audio_file = io.BytesIO(audio_data)
627
- audio_file.name = "audio.wav" # The name is important for the API to recognize the file type
628
 
629
  try:
630
- # Use the automatic_speech_recognition method
631
- response = whisper_api.automatic_speech_recognition(audio=audio_file)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
632
 
633
- # The response should be a dictionary with a 'text' key
634
  return response["text"] if isinstance(response, dict) and "text" in response else str(response)
635
  except Exception as e:
636
  print(f"Error in transcription: {str(e)}")
637
  return f"Error in transcription: {str(e)}"
638
 
 
639
  def vote(data: gr.LikeData):
640
  if data.liked:
641
  print(f"You upvoted this response: {data.value}")
 
28
  ACCOUNT_ID = os.environ.get("CLOUDFARE_ACCOUNT_ID")
29
  API_TOKEN = os.environ.get("CLOUDFLARE_AUTH_TOKEN")
30
  API_BASE_URL = "https://api.cloudflare.com/client/v4/accounts/a17f03e0f049ccae0c15cdcf3b9737ce/ai/run/"
31
+ whisper_api = InferenceClient("openai/whisper-large-v3", token=huggingface_token)
32
 
33
  print(f"ACCOUNT_ID: {ACCOUNT_ID}")
34
  print(f"CLOUDFLARE_AUTH_TOKEN: {API_TOKEN[:5]}..." if API_TOKEN else "Not set")
 
616
  logging.info("Finished generating response")
617
 
618
  def transcribe(audio_file):
619
+ print(f"Received audio file: {audio_file}")
620
  if audio_file is None:
621
+ return "No audio file provided"
 
 
 
 
 
 
 
622
 
623
  try:
624
+ with open(audio_file, "rb") as f:
625
+ audio_data = f.read()
626
+
627
+ print(f"Read {len(audio_data)} bytes from audio file")
628
+
629
+ # Prepare the inputs
630
+ inputs = {
631
+ "audio": audio_data
632
+ }
633
+
634
+ # Prepare the parameters (you can adjust these as needed)
635
+ parameters = {
636
+ "return_timestamps": False,
637
+ "language": "en" # or "auto" for automatic language detection
638
+ }
639
+
640
+ print("Calling automatic_speech_recognition")
641
+
642
+ response = whisper_api.automatic_speech_recognition(
643
+ inputs=inputs,
644
+ parameters=parameters
645
+ )
646
+
647
+ print(f"Received response: {response}")
648
 
 
649
  return response["text"] if isinstance(response, dict) and "text" in response else str(response)
650
  except Exception as e:
651
  print(f"Error in transcription: {str(e)}")
652
  return f"Error in transcription: {str(e)}"
653
 
654
+
655
  def vote(data: gr.LikeData):
656
  if data.liked:
657
  print(f"You upvoted this response: {data.value}")