Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -18,24 +18,6 @@ pipe = pipeline(
|
|
| 18 |
device=device,
|
| 19 |
)
|
| 20 |
|
| 21 |
-
@spaces.GPU
|
| 22 |
-
def respond_to_question(transcript, question):
|
| 23 |
-
# Optionally, use OpenAI API to generate a response to the user's question
|
| 24 |
-
# based on the transcript
|
| 25 |
-
response = ""
|
| 26 |
-
# Replace this with your OpenAI API key
|
| 27 |
-
openai.api_key = os.environ["OPENAI_API_KEY"]
|
| 28 |
-
response = openai.Completion.create(
|
| 29 |
-
engine="gpt-4o-mini",
|
| 30 |
-
prompt=f"Transcript: {transcript}\n\nUser: {question}\n\nAI:",
|
| 31 |
-
temperature=0.3,
|
| 32 |
-
max_tokens=60,
|
| 33 |
-
top_p=1,
|
| 34 |
-
frequency_penalty=0,
|
| 35 |
-
presence_penalty=0
|
| 36 |
-
).choices[0].text
|
| 37 |
-
return response
|
| 38 |
-
|
| 39 |
with gr.Blocks() as transcriberUI:
|
| 40 |
gr.Markdown(
|
| 41 |
"""
|
|
@@ -50,18 +32,36 @@ with gr.Blocks() as transcriberUI:
|
|
| 50 |
response_output = gr.Textbox(label="Response", visible=True)
|
| 51 |
submit_question = gr.Button("Submit question", visible=True)
|
| 52 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 53 |
@spaces.GPU
|
| 54 |
def audio_transcribe(inputs):
|
| 55 |
if inputs is None:
|
| 56 |
raise gr.Error("No audio file submitted! Please upload or record an audio file before submitting your request.")
|
| 57 |
-
|
| 58 |
text = pipe(inputs, batch_size=BATCH_SIZE, return_timestamps=True)["text"]
|
| 59 |
|
| 60 |
return text
|
| 61 |
|
| 62 |
-
def ask_question_callback(
|
| 63 |
if ask_question:
|
| 64 |
-
response = respond_to_question(
|
| 65 |
response_output.value = response
|
| 66 |
else:
|
| 67 |
response_output.value = "No question asked"
|
|
|
|
| 18 |
device=device,
|
| 19 |
)
|
| 20 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 21 |
with gr.Blocks() as transcriberUI:
|
| 22 |
gr.Markdown(
|
| 23 |
"""
|
|
|
|
| 32 |
response_output = gr.Textbox(label="Response", visible=True)
|
| 33 |
submit_question = gr.Button("Submit question", visible=True)
|
| 34 |
|
| 35 |
+
@spaces.GPU
|
| 36 |
+
def respond_to_question(transcript, question):
|
| 37 |
+
# Optionally, use OpenAI API to generate a response to the user's question
|
| 38 |
+
# based on the transcript
|
| 39 |
+
response = ""
|
| 40 |
+
# Replace this with your OpenAI API key
|
| 41 |
+
openai.api_key = os.environ["OPENAI_API_KEY"]
|
| 42 |
+
response = openai.Completion.create(
|
| 43 |
+
engine="gpt-4o-mini",
|
| 44 |
+
prompt=f"Transcript: {transcript}\n\nUser: {question}\n\nAI:",
|
| 45 |
+
temperature=0.3,
|
| 46 |
+
max_tokens=60,
|
| 47 |
+
top_p=1,
|
| 48 |
+
frequency_penalty=0,
|
| 49 |
+
presence_penalty=0
|
| 50 |
+
).choices[0].text
|
| 51 |
+
return response
|
| 52 |
+
|
| 53 |
@spaces.GPU
|
| 54 |
def audio_transcribe(inputs):
|
| 55 |
if inputs is None:
|
| 56 |
raise gr.Error("No audio file submitted! Please upload or record an audio file before submitting your request.")
|
| 57 |
+
|
| 58 |
text = pipe(inputs, batch_size=BATCH_SIZE, return_timestamps=True)["text"]
|
| 59 |
|
| 60 |
return text
|
| 61 |
|
| 62 |
+
def ask_question_callback(transcription,question):
|
| 63 |
if ask_question:
|
| 64 |
+
response = respond_to_question(transcription, question)
|
| 65 |
response_output.value = response
|
| 66 |
else:
|
| 67 |
response_output.value = "No question asked"
|