eddiebee commited on
Commit
efad7dd
·
verified ·
1 Parent(s): 2e2604c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +25 -42
app.py CHANGED
@@ -38,55 +38,38 @@ def generate_challenge(topic, level):
38
  return "Error in generating challenge: " + str(e)
39
 
40
  def tutor_interface(name, experience, goals, topic, request_challenge=False):
41
- # Validate inputs
42
- if not all([name, experience, goals, topic]):
43
- return "Please fill in all required fields."
44
-
45
- # Generate adaptive content
46
  level = assess_knowledge(name, experience, goals)
47
  explanation = generate_explanation(topic, level)
48
-
 
49
  if request_challenge:
50
  challenge = generate_challenge(topic, level)
51
- return f"**Level:** {level}\n\n**Explanation:**\n{explanation}\n\n**Challenge:**\n{challenge}"
52
  else:
53
- return f"**Level:** {level}\n\n**Explanation:**\n{explanation}"
54
-
55
- # Gradio UI setup with theme and structured layout
56
- with gr.Blocks(theme=gr.themes.Soft()) as demo:
57
- gr.Markdown("""
58
- # Adaptive Computer Science Tutor
59
-
60
- Welcome to your personalized Computer Science Tutor! This tutor adapts to your level and learning pace,
61
- offering explanations and practice challenges in areas like data structures, algorithms, and more.
62
-
63
- ### How It Works
64
- 1. Enter your background and goals.
65
- 2. Choose a topic you want to learn.
66
- 3. Get adaptive explanations and challenges suited to your level.
67
- """)
68
-
69
- with gr.Row():
70
- with gr.Column(scale=1):
71
- name = gr.Textbox(label="Your Name", placeholder="Enter your name")
72
- experience = gr.Textbox(label="Programming Experience", placeholder="e.g., Beginner, 2 years Python")
73
-
74
- with gr.Column(scale=1):
75
- goals = gr.Textbox(label="Learning Goals", placeholder="What do you want to achieve?")
76
- topic = gr.Textbox(label="Topic of Interest", placeholder="e.g., Binary Search, Arrays")
77
-
78
- request_challenge = gr.Checkbox(label="Include a practice challenge", value=False)
79
 
80
- # Output display with markdown formatting
81
- output = gr.Markdown(label="Tutor's Response", min_height=30)
82
 
83
- # Submit button
84
- submit_button = gr.Button("Get Started", variant="primary")
85
- submit_button.click(
86
- fn=tutor_interface,
87
- inputs=[name, experience, goals, topic, request_challenge],
88
- outputs=[output]
89
- )
90
 
91
  # Launch the app
92
  if __name__ == "__main__":
 
38
  return "Error in generating challenge: " + str(e)
39
 
40
  def tutor_interface(name, experience, goals, topic, request_challenge=False):
41
+ # Assess knowledge and generate explanation as before
 
 
 
 
42
  level = assess_knowledge(name, experience, goals)
43
  explanation = generate_explanation(topic, level)
44
+
45
+ # Generate challenge if requested
46
  if request_challenge:
47
  challenge = generate_challenge(topic, level)
48
+ return f"Level: {level}\nExplanation:\n{explanation}\n\nChallenge:\n{challenge}"
49
  else:
50
+ return f"Level: {level}\nExplanation:\n{explanation}"
51
+
52
+ # Updated Gradio interface with challenge request option
53
+ with gr.Blocks() as demo:
54
+ gr.Markdown("## Adaptive Computer Science Tutor")
55
+
56
+ # Inputs for user details and topic
57
+ name = gr.Textbox(label="Your Name")
58
+ experience = gr.Textbox(label="Describe your experience with programming.")
59
+ goals = gr.Textbox(label="What are your learning goals?")
60
+ topic = gr.Textbox(label="Topic you'd like to learn about")
61
+ request_challenge = gr.Checkbox(label="Would you like a practice challenge?")
62
+
63
+ # Output
64
+ output = gr.Markdown(label="Tutor's Response")
65
+
66
+ # Submit button
67
+ submit_button = gr.Button("Get Started")
68
+ submit_button.click(tutor_interface, inputs=[name, experience, goals, topic, request_challenge], outputs=output)
 
 
 
 
 
 
 
69
 
70
+ # Launch the interface
71
+ demo.launch()
72
 
 
 
 
 
 
 
 
73
 
74
  # Launch the app
75
  if __name__ == "__main__":