Update app.py
Browse files
app.py
CHANGED
|
@@ -14,13 +14,22 @@ def generate_response(transcribed_text):
|
|
| 14 |
response = openai.ChatCompletion.create(
|
| 15 |
model="gpt-3.5-turbo",
|
| 16 |
messages=[
|
| 17 |
-
{"role": "system", "content": "
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 18 |
{"role": "user", "content": transcribed_text},
|
| 19 |
]
|
| 20 |
)
|
| 21 |
return response['choices'][0]['message']['content']
|
| 22 |
|
| 23 |
-
|
| 24 |
def inference(text):
|
| 25 |
output_file = "tts_output.wav"
|
| 26 |
cmd = ['tts', '--text', text, '--out_path', output_file]
|
|
@@ -31,12 +40,12 @@ def process_audio_and_respond(audio):
|
|
| 31 |
text = transcribe(audio)
|
| 32 |
response_text = generate_response(text)
|
| 33 |
output_file = inference(response_text)
|
| 34 |
-
return output_file
|
| 35 |
|
| 36 |
demo = gr.Interface(
|
| 37 |
process_audio_and_respond,
|
| 38 |
gr.inputs.Audio(source="microphone", type="filepath", label="Speak your question"),
|
| 39 |
-
gr.outputs.Audio(type="filepath", label="Answer"),
|
| 40 |
title="AI Question Answering",
|
| 41 |
description="Ask any question and get an AI-generated answer as audio output.",
|
| 42 |
theme="compact",
|
|
@@ -45,4 +54,4 @@ demo = gr.Interface(
|
|
| 45 |
live=True,
|
| 46 |
)
|
| 47 |
|
| 48 |
-
demo.launch()
|
|
|
|
| 14 |
response = openai.ChatCompletion.create(
|
| 15 |
model="gpt-3.5-turbo",
|
| 16 |
messages=[
|
| 17 |
+
{"role": "system", "content": "Wewe ni mtaalamu wa Kilimo cha mazao, na kilimo cha viazi lishe utajibu maswali yote kwa kiswahili"},
|
| 18 |
+
{"role": "user", "content": "nini maana ya Viazi lishe?"},
|
| 19 |
+
{"role": "assistant", "content": """ viazi lishe ni Viazi vitamu vyenye rangi ya karoti kwa ndani ambavyo vina vitamin A kwa wingi"""},
|
| 20 |
+
{"role": "user", "content": "nini matumizi ya viazi lishe?"},
|
| 21 |
+
{"role": "assistant", "content": """ viazi lishe vinaweza kutengenezea chakula kama Keki,
|
| 22 |
+
Maandazi, Kalimati na tambi: Ukisaga unga wa viazi lishe,
|
| 23 |
+
unaweza kutumika kupika vyakula ambavyo huwa watu
|
| 24 |
+
hutumia unga wa ngano kupika, unga wa viazi lishe una
|
| 25 |
+
virutubisho vingi zaidi kuliko unga wa ngano na
|
| 26 |
+
ukitumika kupikia vyakula tajwa hapo juu watumiaji
|
| 27 |
+
watakuwa wanakula vyakula vyenye virutubisho Zaidi."""},
|
| 28 |
{"role": "user", "content": transcribed_text},
|
| 29 |
]
|
| 30 |
)
|
| 31 |
return response['choices'][0]['message']['content']
|
| 32 |
|
|
|
|
| 33 |
def inference(text):
|
| 34 |
output_file = "tts_output.wav"
|
| 35 |
cmd = ['tts', '--text', text, '--out_path', output_file]
|
|
|
|
| 40 |
text = transcribe(audio)
|
| 41 |
response_text = generate_response(text)
|
| 42 |
output_file = inference(response_text)
|
| 43 |
+
return response_text, output_file
|
| 44 |
|
| 45 |
demo = gr.Interface(
|
| 46 |
process_audio_and_respond,
|
| 47 |
gr.inputs.Audio(source="microphone", type="filepath", label="Speak your question"),
|
| 48 |
+
[gr.outputs.Textbox(label="Answer (text)"), gr.outputs.Audio(type="filepath", label="Answer (audio)")],
|
| 49 |
title="AI Question Answering",
|
| 50 |
description="Ask any question and get an AI-generated answer as audio output.",
|
| 51 |
theme="compact",
|
|
|
|
| 54 |
live=True,
|
| 55 |
)
|
| 56 |
|
| 57 |
+
demo.launch()
|