Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -2,7 +2,7 @@
|
|
2 |
import gradio as gr
|
3 |
import openai
|
4 |
import os
|
5 |
-
import
|
6 |
import base64
|
7 |
|
8 |
OPENAI_API_KEY = os.getenv("OPENAI_API_KEY")
|
@@ -12,7 +12,7 @@ def image_to_base64(img_path):
|
|
12 |
with open(img_path, "rb") as img_file:
|
13 |
return base64.b64encode(img_file.read()).decode('utf-8')
|
14 |
|
15 |
-
img_base64 = image_to_base64("
|
16 |
img_html = f'<img src="data:image/jpg;base64,{img_base64}" alt="SBC6" width="300" style="display: block; margin: auto;"/>'
|
17 |
|
18 |
def predict(question_choice, feedback_level, audio):
|
@@ -22,23 +22,23 @@ def predict(question_choice, feedback_level, audio):
|
|
22 |
message = transcript["text"] # This is the transcribed message from the audio input
|
23 |
|
24 |
# Generate the prompt based on the feedback level
|
25 |
-
feedback_prompt =
|
26 |
|
27 |
# Determine question number based on question_choice
|
28 |
-
question_number =
|
29 |
|
30 |
# Generate the system message based on the question number
|
31 |
-
system_message =
|
32 |
|
33 |
|
34 |
-
# Reference to the picture description from
|
35 |
-
picture_description =
|
36 |
|
37 |
# Determine whether to include the picture description based on the question choice
|
38 |
picture_description_inclusion = f"""
|
39 |
For the first question, ensure your feedback refers to the picture description provided:
|
40 |
{picture_description}
|
41 |
-
""" if question_choice ==
|
42 |
|
43 |
# Construct the conversation with the system and user's message
|
44 |
conversation = [
|
@@ -68,24 +68,22 @@ def predict(question_choice, feedback_level, audio):
|
|
68 |
partial_message = partial_message + chunk['choices'][0]['delta']['content']
|
69 |
yield partial_message
|
70 |
|
71 |
-
# Gradio Interface
|
72 |
iface = gr.Interface(
|
73 |
fn=predict,
|
74 |
inputs=[
|
75 |
-
gr.Radio(
|
76 |
-
gr.Radio(["Brief Feedback", "Moderate Feedback", "Comprehensive Feedback"], label="Choose a feedback level", default="Brief Feedback"),
|
77 |
-
gr.inputs.Audio(source="microphone", type="filepath")
|
78 |
],
|
79 |
-
outputs=gr.inputs.Textbox(),
|
80 |
description=img_html + '''
|
81 |
<div style="text-align: center; font-size: medium;">
|
82 |
<a href="https://forms.moe.edu.sg/forms/J0lmkJ" target="_blank">
|
83 |
📝 Click here to provide feedback on the initial prototype of the Oral Coach 📝
|
84 |
</a>
|
85 |
</div>
|
86 |
-
''',
|
87 |
-
css="custom.css"
|
88 |
)
|
89 |
|
90 |
iface.queue(max_size=99, concurrency_count=40).launch(debug=True)
|
91 |
-
|
|
|
2 |
import gradio as gr
|
3 |
import openai
|
4 |
import os
|
5 |
+
import AlpsData # Importing the AlpsData module
|
6 |
import base64
|
7 |
|
8 |
OPENAI_API_KEY = os.getenv("OPENAI_API_KEY")
|
|
|
12 |
with open(img_path, "rb") as img_file:
|
13 |
return base64.b64encode(img_file.read()).decode('utf-8')
|
14 |
|
15 |
+
img_base64 = image_to_base64("AlpsSBC.JPG")
|
16 |
img_html = f'<img src="data:image/jpg;base64,{img_base64}" alt="SBC6" width="300" style="display: block; margin: auto;"/>'
|
17 |
|
18 |
def predict(question_choice, feedback_level, audio):
|
|
|
22 |
message = transcript["text"] # This is the transcribed message from the audio input
|
23 |
|
24 |
# Generate the prompt based on the feedback level
|
25 |
+
feedback_prompt = AlpsData.generate_prompt(feedback_level)
|
26 |
|
27 |
# Determine question number based on question_choice
|
28 |
+
question_number = AlpsData.questions.index(question_choice) + 1 # New line
|
29 |
|
30 |
# Generate the system message based on the question number
|
31 |
+
system_message = AlpsData.generate_system_message(question_number, feedback_level) # Updated line to include feedback_level
|
32 |
|
33 |
|
34 |
+
# Reference to the picture description from AlpsData.py
|
35 |
+
picture_description = AlpsData.description
|
36 |
|
37 |
# Determine whether to include the picture description based on the question choice
|
38 |
picture_description_inclusion = f"""
|
39 |
For the first question, ensure your feedback refers to the picture description provided:
|
40 |
{picture_description}
|
41 |
+
""" if question_choice == AlpsData.questions[0] else ""
|
42 |
|
43 |
# Construct the conversation with the system and user's message
|
44 |
conversation = [
|
|
|
68 |
partial_message = partial_message + chunk['choices'][0]['delta']['content']
|
69 |
yield partial_message
|
70 |
|
|
|
71 |
iface = gr.Interface(
|
72 |
fn=predict,
|
73 |
inputs=[
|
74 |
+
gr.Radio(AlpsData.questions, label="Choose a question", default=AlpsData.questions[0]), # Updated reference
|
75 |
+
gr.Radio(["Brief Feedback", "Moderate Feedback", "Comprehensive Feedback"], label="Choose a feedback level", default="Brief Feedback"),
|
76 |
+
gr.inputs.Audio(source="microphone", type="filepath")
|
77 |
],
|
78 |
+
outputs=gr.inputs.Textbox(),
|
79 |
description=img_html + '''
|
80 |
<div style="text-align: center; font-size: medium;">
|
81 |
<a href="https://forms.moe.edu.sg/forms/J0lmkJ" target="_blank">
|
82 |
📝 Click here to provide feedback on the initial prototype of the Oral Coach 📝
|
83 |
</a>
|
84 |
</div>
|
85 |
+
''',
|
86 |
+
css="custom.css"
|
87 |
)
|
88 |
|
89 |
iface.queue(max_size=99, concurrency_count=40).launch(debug=True)
|
|