RLikhitha commited on
Commit
77994b5
Β·
verified Β·
1 Parent(s): 39ee121

Create interface/gradio_app.py

Browse files
Files changed (1) hide show
  1. interface/gradio_app.py +156 -0
interface/gradio_app.py ADDED
@@ -0,0 +1,156 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """
2
+ Gradio Interface for EduTutor AI
3
+ """
4
+
5
+ import gradio as gr
6
+
7
+ def create_gradio_interface(ai_tutor, features):
8
+ """Create the main Gradio interface"""
9
+
10
+ def chat_interface(message, subject, difficulty, history):
11
+ if not message.strip():
12
+ return history, history, ""
13
+ response = ai_tutor.generate_response(message, subject, difficulty)
14
+ history.append([message, response])
15
+ return history, history, ""
16
+
17
+ def create_quiz_interface(topic, subject, num_questions):
18
+ if not topic.strip():
19
+ return "Please enter a topic for the quiz.", ""
20
+ quiz_content, session_id = features.create_quiz(topic, subject, int(num_questions))
21
+ return quiz_content, session_id
22
+
23
+ def submit_quiz_interface(session_id, q1, q2, q3, q4, q5, student_name):
24
+ if not session_id:
25
+ return "No active quiz session."
26
+ answers = {"q1": q1, "q2": q2, "q3": q3, "q4": q4, "q5": q5}
27
+ answers = {k: v for k, v in answers.items() if v}
28
+ return features.submit_quiz(session_id, answers, student_name)
29
+
30
+ def homework_analyzer_interface(homework_text, subject):
31
+ if not homework_text.strip():
32
+ return "Please enter your homework."
33
+ return features.homework_analyzer.analyze_homework_comprehensive(homework_text, subject)
34
+
35
+ def study_plan_interface(topic, subject, duration):
36
+ if not topic.strip():
37
+ return "Please enter a topic."
38
+ return features.create_study_plan(topic, subject, duration)
39
+
40
+ def track_progress_interface(student_name, subject, topic, score, activity):
41
+ if not all([student_name.strip(), subject, topic.strip(), activity.strip()]):
42
+ return "Please fill in all fields."
43
+ try:
44
+ score_float = float(score)
45
+ if not 0 <= score_float <= 100:
46
+ return "Score must be between 0 and 100."
47
+ return features.track_progress(student_name, subject, topic, score_float, activity)
48
+ except ValueError:
49
+ return "Please enter a valid score."
50
+
51
+ def view_progress_interface(student_name):
52
+ if not student_name.strip():
53
+ return "Please enter a student name."
54
+ return features.view_progress(student_name)
55
+
56
+ with gr.Blocks(title="πŸŽ“ EduTutor AI", theme=gr.themes.Soft()) as app:
57
+ gr.Markdown("# πŸŽ“ EduTutor AI - Your Complete Learning Companion")
58
+
59
+ with gr.Tabs():
60
+ with gr.TabItem("πŸ€– AI Chat Tutor"):
61
+ with gr.Row():
62
+ chat_subject = gr.Dropdown(
63
+ choices=["Mathematics", "Physics", "Chemistry", "Biology", "General"],
64
+ value="Mathematics", label="πŸ“š Subject"
65
+ )
66
+ chat_difficulty = gr.Dropdown(
67
+ choices=["Beginner", "Intermediate", "Advanced"],
68
+ value="Intermediate", label="🎯 Difficulty"
69
+ )
70
+
71
+ chatbot = gr.Chatbot(label="πŸ’¬ AI Tutor", height=400)
72
+ chat_input = gr.Textbox(placeholder="Ask any question...", label="✍️ Your Question", lines=2)
73
+
74
+ with gr.Row():
75
+ chat_submit = gr.Button("πŸš€ Ask AI Tutor", variant="primary")
76
+ chat_clear = gr.Button("πŸ—‘οΈ Clear Chat")
77
+
78
+ chat_history = gr.State([])
79
+
80
+ chat_submit.click(chat_interface, [chat_input, chat_subject, chat_difficulty, chat_history], [chatbot, chat_history, chat_input])
81
+ chat_input.submit(chat_interface, [chat_input, chat_subject, chat_difficulty, chat_history], [chatbot, chat_history, chat_input])
82
+ chat_clear.click(lambda: ([], []), outputs=[chatbot, chat_history])
83
+
84
+ with gr.TabItem("πŸ“Š Homework Analyzer"):
85
+ homework_subject = gr.Dropdown(
86
+ choices=["Mathematics", "Physics", "Chemistry", "Biology"],
87
+ value="Mathematics", label="πŸ“š Subject"
88
+ )
89
+ homework_input = gr.Textbox(placeholder="Paste your homework here...", label="πŸ“ Homework", lines=8)
90
+ homework_submit = gr.Button("πŸ” Analyze Homework", variant="primary")
91
+ homework_output = gr.Markdown(label="πŸ“Š Analysis", value="Upload homework above for analysis.")
92
+
93
+ homework_submit.click(homework_analyzer_interface, [homework_input, homework_subject], homework_output)
94
+
95
+ with gr.TabItem("πŸ“ Interactive Quiz"):
96
+ with gr.Row():
97
+ quiz_topic = gr.Textbox(placeholder="e.g., Algebra, Photosynthesis", label="πŸ“š Topic")
98
+ quiz_subject = gr.Dropdown(choices=["Mathematics", "Physics", "Chemistry", "Biology"], value="Mathematics", label="🎯 Subject")
99
+ quiz_num_questions = gr.Dropdown(choices=["3", "5"], value="5", label="❓ Questions")
100
+
101
+ create_quiz_btn = gr.Button("πŸ“ Create Quiz", variant="primary")
102
+ quiz_display = gr.Markdown(label="πŸ“ Quiz", value="Click 'Create Quiz' to generate questions.")
103
+ quiz_session_id = gr.Textbox(visible=False)
104
+
105
+ with gr.Row():
106
+ with gr.Column():
107
+ q1_answer = gr.Radio(choices=["A", "B", "C", "D"], label="Question 1")
108
+ q2_answer = gr.Radio(choices=["A", "B", "C", "D"], label="Question 2")
109
+ q3_answer = gr.Radio(choices=["A", "B", "C", "D"], label="Question 3")
110
+ with gr.Column():
111
+ q4_answer = gr.Radio(choices=["A", "B", "C", "D"], label="Question 4")
112
+ q5_answer = gr.Radio(choices=["A", "B", "C", "D"], label="Question 5")
113
+ quiz_student_name = gr.Textbox(placeholder="Your name (optional)", label="πŸ‘€ Name")
114
+
115
+ submit_quiz_btn = gr.Button("πŸ“Š Submit Quiz", variant="secondary")
116
+ quiz_results = gr.Markdown(label="πŸ“Š Results", value="Complete quiz and submit to see results.")
117
+
118
+ create_quiz_btn.click(create_quiz_interface, [quiz_topic, quiz_subject, quiz_num_questions], [quiz_display, quiz_session_id])
119
+ submit_quiz_btn.click(submit_quiz_interface, [quiz_session_id, q1_answer, q2_answer, q3_answer, q4_answer, q5_answer, quiz_student_name], quiz_results)
120
+
121
+ with gr.TabItem("πŸ“‹ Study Plans"):
122
+ with gr.Row():
123
+ plan_topic = gr.Textbox(placeholder="e.g., Linear Equations", label="πŸ“š Topic")
124
+ plan_subject = gr.Dropdown(choices=["Mathematics", "Physics", "Chemistry", "Biology"], value="Mathematics", label="🎯 Subject")
125
+ plan_duration = gr.Dropdown(choices=["1 week", "2 weeks", "1 month"], value="2 weeks", label="⏰ Duration")
126
+
127
+ create_plan_btn = gr.Button("πŸ“‹ Generate Study Plan", variant="primary")
128
+ study_plan_output = gr.Markdown(label="πŸ“‹ Study Plan", value="Enter topic to create personalized study plan.")
129
+
130
+ create_plan_btn.click(study_plan_interface, [plan_topic, plan_subject, plan_duration], study_plan_output)
131
+
132
+ with gr.TabItem("πŸ“ˆ Progress Tracking"):
133
+ with gr.Tabs():
134
+ with gr.TabItem("βž• Add Progress"):
135
+ with gr.Row():
136
+ progress_student = gr.Textbox(placeholder="Student name", label="πŸ‘€ Name")
137
+ progress_subject = gr.Dropdown(choices=["Mathematics", "Physics", "Chemistry", "Biology"], value="Mathematics", label="πŸ“š Subject")
138
+ progress_topic = gr.Textbox(placeholder="e.g., Algebra", label="πŸ“– Topic")
139
+ progress_score = gr.Number(value=85, minimum=0, maximum=100, label="πŸ“Š Score (%)")
140
+ progress_activity = gr.Textbox(placeholder="e.g., Quiz completed", label="πŸ“ Activity")
141
+
142
+ add_progress_btn = gr.Button("βž• Add Progress", variant="primary")
143
+ progress_add_output = gr.Markdown(label="βœ… Update", value="Fill details above to record progress.")
144
+
145
+ add_progress_btn.click(track_progress_interface, [progress_student, progress_subject, progress_topic, progress_score, progress_activity], progress_add_output)
146
+
147
+ with gr.TabItem("πŸ“Š View Progress"):
148
+ view_progress_student = gr.Textbox(placeholder="Student name", label="πŸ‘€ Name")
149
+ view_progress_btn = gr.Button("πŸ“Š Generate Report", variant="primary")
150
+ progress_report_output = gr.Markdown(label="πŸ“ˆ Report", value="Enter student name to view progress.")
151
+
152
+ view_progress_btn.click(view_progress_interface, view_progress_student, progress_report_output)
153
+
154
+ gr.Markdown("---\n## πŸŽ“ About EduTutor AI\nAdvanced AI-powered educational platform for personalized learning.")
155
+
156
+ return app