Update app.py
Browse files
app.py
CHANGED
@@ -1,8 +1,9 @@
|
|
1 |
import gradio as gr
|
2 |
import requests
|
3 |
|
4 |
-
|
5 |
API_KEY = "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"
|
|
|
6 |
HEADERS = {"Authorization": f"Bearer {API_KEY}"}
|
7 |
|
8 |
def transcribe_audio(audio_path: str) -> str:
|
@@ -11,9 +12,21 @@ def transcribe_audio(audio_path: str) -> str:
|
|
11 |
audio_data = f.read()
|
12 |
|
13 |
# Make API request to OpenAI Whisper v2 API
|
14 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
15 |
result = response.json()
|
16 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
17 |
|
18 |
return transcribed_text
|
19 |
|
|
|
1 |
import gradio as gr
|
2 |
import requests
|
3 |
|
4 |
+
# Directly using the API key as it will be deployed in a controlled environment
|
5 |
API_KEY = "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"
|
6 |
+
API_URL = "https://api-inference.huggingface.co/models/openai/whisper-large-v2/whisper"
|
7 |
HEADERS = {"Authorization": f"Bearer {API_KEY}"}
|
8 |
|
9 |
def transcribe_audio(audio_path: str) -> str:
|
|
|
12 |
audio_data = f.read()
|
13 |
|
14 |
# Make API request to OpenAI Whisper v2 API
|
15 |
+
try:
|
16 |
+
response = requests.post(API_URL, headers=HEADERS, data=audio_data)
|
17 |
+
response.raise_for_status() # Raises an HTTPError if the HTTP request returned an unsuccessful status code
|
18 |
+
except requests.RequestException as error:
|
19 |
+
print(f"API request failed: {error}")
|
20 |
+
return "Failed to transcribe. Please try again."
|
21 |
+
|
22 |
result = response.json()
|
23 |
+
|
24 |
+
# Print the full JSON response for troubleshooting
|
25 |
+
print(result)
|
26 |
+
|
27 |
+
# Extract the transcribed text from the response
|
28 |
+
# TODO: Replace 'your-key-here' with the actual key used by the API's response
|
29 |
+
transcribed_text = result.get("your-key-here", "Failed to retrieve transcription.")
|
30 |
|
31 |
return transcribed_text
|
32 |
|