Update app.py
Browse files
app.py
CHANGED
@@ -0,0 +1,103 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
from utils.quiz_generator import generate_quiz
|
3 |
+
from utils.chatbot import ask_ai
|
4 |
+
from utils.summarizer import summarize_text, get_youtube_transcript, extract_text_from_pdf
|
5 |
+
from utils.translator import translate_text
|
6 |
+
from utils.plagiarism_checker import check_plagiarism
|
7 |
+
from utils.weakness_analyzer import analyze_weakness
|
8 |
+
from utils.engagement_predictor import predict_engagement
|
9 |
+
from utils.badge import assign_badges
|
10 |
+
|
11 |
+
# Chat history for chatbot
|
12 |
+
chat_history = []
|
13 |
+
|
14 |
+
# ------------------- Gradio UI -------------------
|
15 |
+
|
16 |
+
with gr.Blocks(title="π Smart LMS AI Suite") as demo:
|
17 |
+
|
18 |
+
gr.Markdown("# π Smart LMS AI Suite\nYour AI-powered Learning Assistant π")
|
19 |
+
|
20 |
+
with gr.Tabs():
|
21 |
+
|
22 |
+
# 1. Quiz Generator
|
23 |
+
with gr.TabItem("π§ Quiz Generator"):
|
24 |
+
with gr.Row():
|
25 |
+
topic_input = gr.Textbox(label="Paste Topic Content")
|
26 |
+
num_qs = gr.Slider(1, 10, value=5, label="Number of Questions")
|
27 |
+
quiz_output = gr.Textbox(label="Generated Quiz")
|
28 |
+
quiz_button = gr.Button("Generate Quiz")
|
29 |
+
quiz_button.click(fn=generate_quiz, inputs=[topic_input, num_qs], outputs=quiz_output)
|
30 |
+
|
31 |
+
# 2. AI Teaching Assistant
|
32 |
+
with gr.TabItem("π€ AI Teaching Assistant"):
|
33 |
+
with gr.Row():
|
34 |
+
question_input = gr.Textbox(label="Ask your question")
|
35 |
+
chatbot_output = gr.Textbox(label="AI Answer")
|
36 |
+
chat_button = gr.Button("Ask")
|
37 |
+
def chat_interface(q):
|
38 |
+
global chat_history
|
39 |
+
response, chat_history = ask_ai(q, chat_history)
|
40 |
+
return response
|
41 |
+
chat_button.click(fn=chat_interface, inputs=question_input, outputs=chatbot_output)
|
42 |
+
|
43 |
+
# 3. Summarizer
|
44 |
+
with gr.TabItem("π Summarizer"):
|
45 |
+
with gr.Row():
|
46 |
+
summarizer_input = gr.Textbox(lines=4, label="Paste Text to Summarize")
|
47 |
+
yt_url = gr.Textbox(label="Or Enter YouTube Video URL")
|
48 |
+
pdf_input = gr.File(label="Or Upload PDF", file_types=[".pdf"])
|
49 |
+
summary_output = gr.Textbox(label="Summary")
|
50 |
+
summary_button = gr.Button("Summarize")
|
51 |
+
|
52 |
+
def summarize_all(text, url, pdf):
|
53 |
+
if pdf:
|
54 |
+
content = extract_text_from_pdf(pdf.name)
|
55 |
+
elif url:
|
56 |
+
content = get_youtube_transcript(url)
|
57 |
+
else:
|
58 |
+
content = text
|
59 |
+
return summarize_text(content)
|
60 |
+
|
61 |
+
summary_button.click(fn=summarize_all, inputs=[summarizer_input, yt_url, pdf_input], outputs=summary_output)
|
62 |
+
|
63 |
+
# 4. Translator
|
64 |
+
with gr.TabItem("π Translator"):
|
65 |
+
text_input = gr.Textbox(label="Enter English Text")
|
66 |
+
lang = gr.Dropdown(choices=["te", "hi", "ta", "bn", "kn", "gu", "ur"], label="Target Language")
|
67 |
+
translated = gr.Textbox(label="Translated Text")
|
68 |
+
translate_button = gr.Button("Translate")
|
69 |
+
translate_button.click(fn=translate_text, inputs=[text_input, lang], outputs=translated)
|
70 |
+
|
71 |
+
# 5. Plagiarism Checker
|
72 |
+
with gr.TabItem("π΅οΈ Plagiarism Checker"):
|
73 |
+
with gr.Row():
|
74 |
+
plag_input1 = gr.Textbox(label="Text 1")
|
75 |
+
plag_input2 = gr.Textbox(label="Text 2")
|
76 |
+
plag_output = gr.Textbox(label="Plagiarism Result")
|
77 |
+
plag_btn = gr.Button("Check")
|
78 |
+
plag_btn.click(fn=check_plagiarism, inputs=[plag_input1, plag_input2], outputs=plag_output)
|
79 |
+
|
80 |
+
# 6. Weakness Analyzer
|
81 |
+
with gr.TabItem("π Weakness Analyzer"):
|
82 |
+
weakness_file = gr.File(label="Upload Quiz Scores CSV")
|
83 |
+
weakness_result = gr.Textbox(label="Analysis Result")
|
84 |
+
weakness_btn = gr.Button("Analyze")
|
85 |
+
weakness_btn.click(fn=analyze_weakness, inputs=weakness_file, outputs=weakness_result)
|
86 |
+
|
87 |
+
# 7. Engagement Predictor
|
88 |
+
with gr.TabItem("π Engagement Predictor"):
|
89 |
+
engagement_file = gr.File(label="Upload Student Log CSV")
|
90 |
+
engagement_output = gr.Textbox(label="Prediction Report")
|
91 |
+
engagement_btn = gr.Button("Predict Engagement")
|
92 |
+
engagement_btn.click(fn=predict_engagement, inputs=engagement_file, outputs=engagement_output)
|
93 |
+
|
94 |
+
# 8. Badge Generator
|
95 |
+
with gr.TabItem("π
Badge Generator"):
|
96 |
+
badge_file = gr.File(label="Upload Performance CSV")
|
97 |
+
badge_output = gr.Textbox(label="Badge Report")
|
98 |
+
badge_btn = gr.Button("Generate Badges")
|
99 |
+
badge_btn.click(fn=assign_badges, inputs=badge_file, outputs=badge_output)
|
100 |
+
|
101 |
+
|
102 |
+
# π Launch
|
103 |
+
demo.launch()
|