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