Spaces:
Runtime error
Runtime error
init repo
Browse files- README.md +1 -12
- app.py +39 -0
- requirements.txt +3 -0
README.md
CHANGED
|
@@ -1,12 +1 @@
|
|
| 1 |
-
|
| 2 |
-
title: Speech Recognition
|
| 3 |
-
emoji: ๐ฅ
|
| 4 |
-
colorFrom: pink
|
| 5 |
-
colorTo: yellow
|
| 6 |
-
sdk: gradio
|
| 7 |
-
sdk_version: 4.26.0
|
| 8 |
-
app_file: app.py
|
| 9 |
-
pinned: false
|
| 10 |
-
---
|
| 11 |
-
|
| 12 |
-
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
|
|
|
| 1 |
+
# speech_recognition
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
app.py
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
import gradio as gr
|
| 3 |
+
from dotenv import load_dotenv
|
| 4 |
+
from openai import OpenAI
|
| 5 |
+
|
| 6 |
+
load_dotenv()
|
| 7 |
+
client = OpenAI(api_key=os.getenv("OPENAI_API_KEY"))
|
| 8 |
+
|
| 9 |
+
def transcribe(file_path):
|
| 10 |
+
audio_file = open(file_path, "rb")
|
| 11 |
+
transcription = client.audio.transcriptions.create(
|
| 12 |
+
model="whisper-1",
|
| 13 |
+
file=audio_file
|
| 14 |
+
)
|
| 15 |
+
audio_file.close()
|
| 16 |
+
return transcription.text
|
| 17 |
+
|
| 18 |
+
def clear_transcription():
|
| 19 |
+
return ""
|
| 20 |
+
|
| 21 |
+
def clear_audio(recording):
|
| 22 |
+
return None
|
| 23 |
+
|
| 24 |
+
with gr.Blocks(theme=gr.themes.Soft()) as demo:
|
| 25 |
+
gr.Markdown("# EpicAI ้ณๅฃฐ่ช่ญAI")
|
| 26 |
+
with gr.Row():
|
| 27 |
+
with gr.Column():
|
| 28 |
+
audio_input = gr.Audio(source="microphone", type="filepath", label="้ณๅฃฐใ้ฒ้ณ")
|
| 29 |
+
submit_button = gr.Button("้ณๅฃฐ่ช่ญใๅฎ่ก")
|
| 30 |
+
clear_audio_button = gr.Button("ๅ
ฅๅ้ณๅฃฐใใฏใชใข")
|
| 31 |
+
with gr.Column():
|
| 32 |
+
transcription_output = gr.Textbox(label="้ณๅฃฐ่ช่ญ็ตๆ", elem_id="transcription_output")
|
| 33 |
+
clear_transcription_button = gr.Button("็ตๆใใฏใชใข", elem_id="clear_transcription_button")
|
| 34 |
+
|
| 35 |
+
submit_button.click(transcribe, inputs=audio_input, outputs=transcription_output)
|
| 36 |
+
clear_audio_button.click(clear_audio, inputs=audio_input, outputs=audio_input)
|
| 37 |
+
clear_transcription_button.click(clear_transcription, inputs=None, outputs=transcription_output)
|
| 38 |
+
|
| 39 |
+
demo.launch(share=True)
|
requirements.txt
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
gradio==3.50.2
|
| 2 |
+
openai==1.17.1
|
| 3 |
+
python-dotenv==1.0.1
|