simonraj commited on
Commit
364fbfd
1 Parent(s): aff19d1

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +15 -12
app.py CHANGED
@@ -14,31 +14,31 @@ def image_to_base64(img_path):
14
  img_base64 = image_to_base64("SBC6.jpg")
15
  img_html = f'<img src="data:image/jpg;base64,{img_base64}" alt="SBC6" width="300" style="display: block; margin: auto;"/>'
16
 
17
-
18
  def predict(question_choice, audio):
19
  # Transcribe the audio using Whisper
20
  with open(audio, "rb") as audio_file:
21
  transcript = openai.Audio.transcribe("whisper-1", audio_file)
 
22
 
23
- message = transcript["text"]
24
-
25
  # Generate the system message based on the chosen question
26
  current_question_index = data6.questions.index(question_choice)
 
27
 
28
  # Construct the conversation with the system and user's message
29
  conversation = [
30
- {
31
- "role": "system",
32
- "content": f"You are an expert English Language Teacher in a Singapore Primary school, directly guiding a Primary 6 student in Singapore. The student is answering the question: '{data6.questions[current_question_index]}'. Based on their response, provide direct feedback to help them improve their spoken skills. Emphasize areas of strength, suggest areas of improvement, and guide them on how to better answer using the {data6.strategy_text[current_question_index][0]} strategy. The feedback should be in second person, addressing the student directly."
33
- },
34
- {"role": "user", "content": message}
35
- ]
 
36
 
37
  response = openai.ChatCompletion.create(
38
  model='gpt-3.5-turbo',
39
  messages=conversation,
40
- temperature=0.7,
41
- max_tokens=300, # Limiting the response to 400 tokens
42
  stream=True
43
  )
44
 
@@ -48,9 +48,11 @@ def predict(question_choice, audio):
48
  partial_message = partial_message + chunk['choices'][0]['delta']['content']
49
  yield partial_message
50
 
 
51
  def get_image_html():
52
  return "![](SBC6.jpg)" # Markdown syntax to embed the image
53
 
 
54
  # Gradio Interface
55
  iface = gr.Interface(
56
  fn=predict,
@@ -59,7 +61,8 @@ iface = gr.Interface(
59
  gr.inputs.Audio(source="microphone", type="filepath") # Audio input
60
  ],
61
  outputs=gr.inputs.Textbox(), # Using inputs.Textbox as an output to make it editable
62
- description=img_html
 
63
  )
64
  iface.queue().launch()
65
 
 
14
  img_base64 = image_to_base64("SBC6.jpg")
15
  img_html = f'<img src="data:image/jpg;base64,{img_base64}" alt="SBC6" width="300" style="display: block; margin: auto;"/>'
16
 
 
17
  def predict(question_choice, audio):
18
  # Transcribe the audio using Whisper
19
  with open(audio, "rb") as audio_file:
20
  transcript = openai.Audio.transcribe("whisper-1", audio_file)
21
+ message = transcript["text"] # This is the transcribed message from the audio input
22
 
 
 
23
  # Generate the system message based on the chosen question
24
  current_question_index = data6.questions.index(question_choice)
25
+ strategy, explanation = data6.strategy_text[current_question_index]
26
 
27
  # Construct the conversation with the system and user's message
28
  conversation = [
29
+ {
30
+ "role": "system",
31
+ "content": f"You are an expert English Language Teacher in a Singapore Primary school, directly guiding a Primary 6 student in Singapore. The student is answering the question: '{data6.questions[current_question_index]}'. Point out areas they did well and where they can improve. Then, provide a suggested answer using the {data6.strategy_text[current_question_index][0]} strategy. Encourage the use of sophisticated vocabulary and expressions. For the second and third questions, the picture is not relevant, so the student should not refer to it in their response. {explanation} The feedback should be in second person, addressing the student directly."
32
+ },
33
+ {"role": "user", "content": message}
34
+ ]
35
+
36
 
37
  response = openai.ChatCompletion.create(
38
  model='gpt-3.5-turbo',
39
  messages=conversation,
40
+ temperature=0.4,
41
+ max_tokens=400, # Limiting the response to 500 tokens
42
  stream=True
43
  )
44
 
 
48
  partial_message = partial_message + chunk['choices'][0]['delta']['content']
49
  yield partial_message
50
 
51
+
52
  def get_image_html():
53
  return "![](SBC6.jpg)" # Markdown syntax to embed the image
54
 
55
+
56
  # Gradio Interface
57
  iface = gr.Interface(
58
  fn=predict,
 
61
  gr.inputs.Audio(source="microphone", type="filepath") # Audio input
62
  ],
63
  outputs=gr.inputs.Textbox(), # Using inputs.Textbox as an output to make it editable
64
+ description=img_html,
65
+ css="custom.css" # Link to the custom CSS file
66
  )
67
  iface.queue().launch()
68