SameerArz commited on
Commit
0c55aa6
·
verified ·
1 Parent(s): 9adfa1a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +14 -15
app.py CHANGED
@@ -1,35 +1,31 @@
 
 
1
  import gradio as gr
2
- from utils import generate_tutor_output # Import the function from utils.py
3
 
4
  with gr.Blocks() as demo:
5
- gr.Markdown("# 🎓 MistralMind: A precision AI for personalized learning and development")
6
-
7
  with gr.Row():
8
  with gr.Column(scale=2):
9
- # Subject Dropdown
10
  subject = gr.Dropdown(
11
  ["Math", "Science", "History", "Literature", "Code", "AI"],
12
  label="Subject",
13
  info="Choose the subject of your lesson"
14
  )
15
-
16
- # Difficulty Level Radio
17
  difficulty = gr.Radio(
18
  ["Beginner", "Intermediate", "Advanced"],
19
  label="Difficulty Level",
20
  info="Select your proficiency level"
21
  )
22
-
23
- # Student Input Textbox
24
  student_input = gr.Textbox(
25
  placeholder="Type your query here...",
26
  label="Your Input",
27
  info="Enter the topic you want to learn"
28
  )
29
 
30
- # Model Dropdown - Updated to match models in utils.py
31
  model = gr.Dropdown(
32
- ["OpenAI", "Meta-Llama-3.1-8B-Instruct", "Meta-Llama-3.3-70B", "Mixtral 8x7B"],
33
  label="LLM",
34
  info="Choose the language model"
35
  )
@@ -40,28 +36,31 @@ with gr.Blocks() as demo:
40
  lesson_output = gr.Markdown(label="Lesson")
41
  question_output = gr.Markdown(label="Comprehension Question")
42
  feedback_output = gr.Markdown(label="Feedback")
 
43
 
44
  gr.Markdown("""
45
  ### How to Use
46
  1. Select a subject from the dropdown.
47
  2. Choose your difficulty level.
48
  3. Enter the topic or question you'd like to explore.
49
- 4. Click 'Generate Lesson' to receive a personalized lesson, question, and feedback.
50
  5. Review the AI-generated content to enhance your learning.
51
  6. Feel free to ask follow-up questions or explore new topics!
52
  """)
53
-
 
54
  def process_output(output):
55
  try:
56
- parsed = eval(output) # Parse the output as JSON
57
  return parsed["lesson"], parsed["question"], parsed["feedback"]
58
  except:
59
  return "Error parsing output", "No question available", "No feedback available"
60
-
 
61
  submit_button.click(
62
  fn=lambda s, d, i, m: process_output(generate_tutor_output(s, d, i, m)),
63
  inputs=[subject, difficulty, student_input, model],
64
- outputs=[lesson_output, question_output, feedback_output]
65
  )
66
 
67
  if __name__ == "__main__":
 
1
+ # app.py
2
+
3
  import gradio as gr
4
+ from utils import generate_tutor_output
5
 
6
  with gr.Blocks() as demo:
7
+ gr.Markdown("# 🎓 Your AI Tutor by Farhan")
8
+
9
  with gr.Row():
10
  with gr.Column(scale=2):
 
11
  subject = gr.Dropdown(
12
  ["Math", "Science", "History", "Literature", "Code", "AI"],
13
  label="Subject",
14
  info="Choose the subject of your lesson"
15
  )
 
 
16
  difficulty = gr.Radio(
17
  ["Beginner", "Intermediate", "Advanced"],
18
  label="Difficulty Level",
19
  info="Select your proficiency level"
20
  )
 
 
21
  student_input = gr.Textbox(
22
  placeholder="Type your query here...",
23
  label="Your Input",
24
  info="Enter the topic you want to learn"
25
  )
26
 
 
27
  model = gr.Dropdown(
28
+ ["OpenAI", "LLAMA3 70B", "Mixtral 8x7B"],
29
  label="LLM",
30
  info="Choose the language model"
31
  )
 
36
  lesson_output = gr.Markdown(label="Lesson")
37
  question_output = gr.Markdown(label="Comprehension Question")
38
  feedback_output = gr.Markdown(label="Feedback")
39
+ image_output = gr.Image(label="Visual Answer", elem_id="image-output")
40
 
41
  gr.Markdown("""
42
  ### How to Use
43
  1. Select a subject from the dropdown.
44
  2. Choose your difficulty level.
45
  3. Enter the topic or question you'd like to explore.
46
+ 4. Click 'Generate Lesson' to receive a personalized lesson, question, feedback, and a visual answer.
47
  5. Review the AI-generated content to enhance your learning.
48
  6. Feel free to ask follow-up questions or explore new topics!
49
  """)
50
+
51
+ # Function to process and extract the JSON response
52
  def process_output(output):
53
  try:
54
+ parsed = eval(output)
55
  return parsed["lesson"], parsed["question"], parsed["feedback"]
56
  except:
57
  return "Error parsing output", "No question available", "No feedback available"
58
+
59
+ # Define the interaction between user inputs and generated outputs
60
  submit_button.click(
61
  fn=lambda s, d, i, m: process_output(generate_tutor_output(s, d, i, m)),
62
  inputs=[subject, difficulty, student_input, model],
63
+ outputs=[lesson_output, question_output, feedback_output, image_output]
64
  )
65
 
66
  if __name__ == "__main__":