Spaces:
Build error
Build error
Update app.py
Browse filesAdded ask_question feature w/ OpenAI text-davinci-002
app.py
CHANGED
@@ -1,3 +1,4 @@
|
|
|
|
1 |
import spaces
|
2 |
import torch
|
3 |
import gradio as gr
|
@@ -23,8 +24,37 @@ def audio_transcribe(inputs, task):
|
|
23 |
raise gr.Error("No audio file submitted! Please upload or record an audio file before submitting your request.")
|
24 |
|
25 |
text = pipe(inputs, batch_size=BATCH_SIZE, generate_kwargs={"task": task}, return_timestamps=True)["text"]
|
|
|
|
|
26 |
return text
|
27 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
28 |
with gr.Blocks() as transcriberUI:
|
29 |
gr.Markdown(
|
30 |
"""
|
@@ -34,6 +64,12 @@ with gr.Blocks() as transcriberUI:
|
|
34 |
""")
|
35 |
inp = gr.File(label="Arquivo de Audio", show_label=True, type="filepath", file_count="single", file_types=["mp3"])
|
36 |
transcribe = gr.Textbox(label="Transcricao", show_label=True, show_copy_button=True)
|
|
|
|
|
|
|
|
|
37 |
inp.upload(audio_transcribe, inp, transcribe)
|
|
|
|
|
38 |
|
39 |
transcriberUI.queue().launch()
|
|
|
1 |
+
import os
|
2 |
import spaces
|
3 |
import torch
|
4 |
import gradio as gr
|
|
|
24 |
raise gr.Error("No audio file submitted! Please upload or record an audio file before submitting your request.")
|
25 |
|
26 |
text = pipe(inputs, batch_size=BATCH_SIZE, generate_kwargs={"task": task}, return_timestamps=True)["text"]
|
27 |
+
ask_question.visible = True
|
28 |
+
|
29 |
return text
|
30 |
|
31 |
+
@spaces.GPU
|
32 |
+
def respond_to_question(transcript, question):
|
33 |
+
# Optionally, use OpenAI API to generate a response to the user's question
|
34 |
+
# based on the transcript
|
35 |
+
response = ""
|
36 |
+
# Replace this with your OpenAI API key
|
37 |
+
openai.api_key = os.environ["OPENAI_API_KEY"]
|
38 |
+
response = openai.Completion.create(
|
39 |
+
engine="text-davinci-002",
|
40 |
+
prompt=f"Transcript: {transcript}\n\nUser: {question}\n\nAI:",
|
41 |
+
temperature=0.7,
|
42 |
+
max_tokens=60,
|
43 |
+
top_p=1,
|
44 |
+
frequency_penalty=0,
|
45 |
+
presence_penalty=0
|
46 |
+
).choices[0].text
|
47 |
+
return response
|
48 |
+
|
49 |
+
def ask_question_callback():
|
50 |
+
if ask_question.value:
|
51 |
+
response = respond_to_question(transcript_output.value, ask_question.value)
|
52 |
+
response_output.visible = True
|
53 |
+
response_output.value = response
|
54 |
+
else:
|
55 |
+
response_output.value = "No question asked"
|
56 |
+
|
57 |
+
|
58 |
with gr.Blocks() as transcriberUI:
|
59 |
gr.Markdown(
|
60 |
"""
|
|
|
64 |
""")
|
65 |
inp = gr.File(label="Arquivo de Audio", show_label=True, type="filepath", file_count="single", file_types=["mp3"])
|
66 |
transcribe = gr.Textbox(label="Transcricao", show_label=True, show_copy_button=True)
|
67 |
+
ask_question = gr.Textbox(label="Ask a question", visible=False)
|
68 |
+
response_output = gr.Textbox(label="Response", visible=False)
|
69 |
+
submit_question = gr.Button("Submit question")
|
70 |
+
|
71 |
inp.upload(audio_transcribe, inp, transcribe)
|
72 |
+
submit_question.click(ask_question_callback, outputs=[response_output], inputs=[transcribe, ask_question])
|
73 |
+
|
74 |
|
75 |
transcriberUI.queue().launch()
|