Update app.py
Browse files
app.py
CHANGED
|
@@ -14,24 +14,31 @@ client = OpenAI(api_key = OPENAI_SECRET_KEY)
|
|
| 14 |
|
| 15 |
|
| 16 |
###################### Choose Question Type
|
| 17 |
-
|
| 18 |
-
"
|
| 19 |
-
"
|
| 20 |
-
"Difficile": "Simple.txt"
|
| 21 |
}
|
| 22 |
|
| 23 |
-
def generate_question(
|
| 24 |
|
| 25 |
######################## Create Sample Question ##################
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 29 |
question = client.chat.completions.create(model="gpt-3.5-turbo-1106", temperature=1, messages=messages)
|
| 30 |
question_text=question.choices[0].message.content
|
| 31 |
return question_text
|
| 32 |
|
| 33 |
|
| 34 |
-
def transcribe(recorder):
|
| 35 |
audio_data, sr = sf.read(recorder)
|
| 36 |
with sf.SoundFile("Audio_Files/test.mp3", mode='w', samplerate=sr, channels=len(audio_data.shape)) as file:
|
| 37 |
file.write(audio_data)
|
|
@@ -57,11 +64,17 @@ def transcribe(recorder):
|
|
| 57 |
|
| 58 |
|
| 59 |
####################################Ask OpenAI to provide feedback on audio response
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 65 |
|
| 66 |
messages = [{"role": "system", "content": role},
|
| 67 |
{"role": "user", "content": audio_transcript.text }
|
|
@@ -89,7 +102,7 @@ def transcribe(recorder):
|
|
| 89 |
with gr.Blocks() as demo:
|
| 90 |
output_file = "Audio_Files/speech.mp3"
|
| 91 |
|
| 92 |
-
q_type = gr.Radio(["Simple","Moyenne","Difficile"], show_label=False
|
| 93 |
|
| 94 |
txt = gr.Textbox(label="Question")
|
| 95 |
btn = gr.Button(value="Generate Question")
|
|
|
|
| 14 |
|
| 15 |
|
| 16 |
###################### Choose Question Type
|
| 17 |
+
language_type_map = {
|
| 18 |
+
"French": "FrenchTutor.txt",
|
| 19 |
+
"Spanish": "SpanishTutor.txt",
|
|
|
|
| 20 |
}
|
| 21 |
|
| 22 |
+
def generate_question(language_type):
|
| 23 |
|
| 24 |
######################## Create Sample Question ##################
|
| 25 |
+
if language_type_map == French:
|
| 26 |
+
messages = [
|
| 27 |
+
{"role": "system", "content": "Vous etes un machine de questions qui cree des questions pour stimuler un reponse d'un etudiant intermediate de francais. La question doit avoir du context, mais le context pourrait etre n'importe quoi. Favourizez les contexts quotidiens et eviter les suject touristiques. Donnez le context suivi par la question."},
|
| 28 |
+
{"role": "user", "content": "Donnez moi le context et la question."}
|
| 29 |
+
]
|
| 30 |
+
else:
|
| 31 |
+
messages = [
|
| 32 |
+
{"role": "system", "content": "Eres una máquina de preguntas que crea preguntas para estimular una respuesta de un estudiante intermedio de francés. La pregunta debe tener un contexto, pero el contexto puede ser cualquier cosa. Favorece los contextos cotidianos y evita los temas turísticos. Proporciona el contexto seguido de la pregunta."},
|
| 33 |
+
{"role": "user", "content": "Proporcióneme el contexto y la pregunta."}
|
| 34 |
+
]
|
| 35 |
+
|
| 36 |
question = client.chat.completions.create(model="gpt-3.5-turbo-1106", temperature=1, messages=messages)
|
| 37 |
question_text=question.choices[0].message.content
|
| 38 |
return question_text
|
| 39 |
|
| 40 |
|
| 41 |
+
def transcribe(recorder,language_type):
|
| 42 |
audio_data, sr = sf.read(recorder)
|
| 43 |
with sf.SoundFile("Audio_Files/test.mp3", mode='w', samplerate=sr, channels=len(audio_data.shape)) as file:
|
| 44 |
file.write(audio_data)
|
|
|
|
| 64 |
|
| 65 |
|
| 66 |
####################################Ask OpenAI to provide feedback on audio response
|
| 67 |
+
|
| 68 |
+
if language_type_map == French:
|
| 69 |
+
with open("Format_Library/FrenchTutor.txt", "r") as f:
|
| 70 |
+
role = f.read()
|
| 71 |
+
else if language_type_map == Spanish:
|
| 72 |
+
with open("Format_Library/SpanishTutor.txt", "r") as f:
|
| 73 |
+
role = f.read()
|
| 74 |
+
else:
|
| 75 |
+
with open("Format_Library/FrenchTutor.txt", "r") as f:
|
| 76 |
+
role = f.read()
|
| 77 |
+
print(role)
|
| 78 |
|
| 79 |
messages = [{"role": "system", "content": role},
|
| 80 |
{"role": "user", "content": audio_transcript.text }
|
|
|
|
| 102 |
with gr.Blocks() as demo:
|
| 103 |
output_file = "Audio_Files/speech.mp3"
|
| 104 |
|
| 105 |
+
q_type = gr.Radio(["Simple","Moyenne","Difficile"], show_label=False)
|
| 106 |
|
| 107 |
txt = gr.Textbox(label="Question")
|
| 108 |
btn = gr.Button(value="Generate Question")
|