Spaces:
Sleeping
Sleeping
Commit
·
dc4a3e4
1
Parent(s):
790c6bd
Create chatbot.py
Browse files- chatbot.py +39 -0
chatbot.py
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import openai
|
| 2 |
+
import gradio as gr
|
| 3 |
+
import warnings
|
| 4 |
+
|
| 5 |
+
warnings.filterwarnings("ignore")
|
| 6 |
+
openai.api_key = "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"
|
| 7 |
+
|
| 8 |
+
|
| 9 |
+
def transcribe(audio, text):
|
| 10 |
+
if audio is not None:
|
| 11 |
+
with open(audio, "rb") as transcript:
|
| 12 |
+
prompt = openai.Audio.transcribe("whisper-1", transcript)
|
| 13 |
+
s = prompt["text"]
|
| 14 |
+
else:
|
| 15 |
+
s = text
|
| 16 |
+
|
| 17 |
+
response = openai.Completion.create(
|
| 18 |
+
engine="text-davinci-002",
|
| 19 |
+
prompt=s,
|
| 20 |
+
max_tokens=60,
|
| 21 |
+
n=1,
|
| 22 |
+
stop=None,
|
| 23 |
+
temperature=0.5,
|
| 24 |
+
)
|
| 25 |
+
r = response.choices[0].text
|
| 26 |
+
|
| 27 |
+
return [s,r]
|
| 28 |
+
|
| 29 |
+
|
| 30 |
+
with gr.Blocks() as demo:
|
| 31 |
+
gr.Markdown("Boba Jarvis strikes again")
|
| 32 |
+
with gr.Row():
|
| 33 |
+
input1 = gr.inputs.Audio(source="microphone", type = "filepath", label="Use your voice to chat")
|
| 34 |
+
input2 = gr.inputs.Textbox(lines=7, label="Chat with AI")
|
| 35 |
+
output_1 = gr.Textbox(label = "Speech to Text")
|
| 36 |
+
output_2 = gr.Textbox(label = "AI Output")
|
| 37 |
+
btn = gr.Button("Run")
|
| 38 |
+
btn.click(fn=transcribe, inputs=[input1, input2], outputs=[output_1, output_2])
|
| 39 |
+
demo.launch(share=True)
|