File size: 4,673 Bytes
f678735
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import gradio as gr
from utils.quiz_generator import generate_quiz
from utils.chatbot import ask_ai
from utils.summarizer import summarize_text, get_youtube_transcript, extract_text_from_pdf
from utils.translator import translate_text
from utils.plagiarism_checker import check_plagiarism
from utils.weakness_analyzer import analyze_weakness
from utils.engagement_predictor import predict_engagement
from utils.badge import assign_badges

# Chat history for chatbot
chat_history = []

# ------------------- Gradio UI -------------------

with gr.Blocks(title="πŸ“š Smart LMS AI Suite") as demo:

    gr.Markdown("# πŸŽ“ Smart LMS AI Suite\nYour AI-powered Learning Assistant πŸš€")

    with gr.Tabs():
        
        # 1. Quiz Generator
        with gr.TabItem("🧠 Quiz Generator"):
            with gr.Row():
                topic_input = gr.Textbox(label="Paste Topic Content")
                num_qs = gr.Slider(1, 10, value=5, label="Number of Questions")
            quiz_output = gr.Textbox(label="Generated Quiz")
            quiz_button = gr.Button("Generate Quiz")
            quiz_button.click(fn=generate_quiz, inputs=[topic_input, num_qs], outputs=quiz_output)

        # 2. AI Teaching Assistant
        with gr.TabItem("πŸ€– AI Teaching Assistant"):
            with gr.Row():
                question_input = gr.Textbox(label="Ask your question")
                chatbot_output = gr.Textbox(label="AI Answer")
            chat_button = gr.Button("Ask")
            def chat_interface(q):
                global chat_history
                response, chat_history = ask_ai(q, chat_history)
                return response
            chat_button.click(fn=chat_interface, inputs=question_input, outputs=chatbot_output)

        # 3. Summarizer
        with gr.TabItem("πŸ“„ Summarizer"):
            with gr.Row():
                summarizer_input = gr.Textbox(lines=4, label="Paste Text to Summarize")
                yt_url = gr.Textbox(label="Or Enter YouTube Video URL")
                pdf_input = gr.File(label="Or Upload PDF", file_types=[".pdf"])
            summary_output = gr.Textbox(label="Summary")
            summary_button = gr.Button("Summarize")

            def summarize_all(text, url, pdf):
                if pdf:
                    content = extract_text_from_pdf(pdf.name)
                elif url:
                    content = get_youtube_transcript(url)
                else:
                    content = text
                return summarize_text(content)
                
            summary_button.click(fn=summarize_all, inputs=[summarizer_input, yt_url, pdf_input], outputs=summary_output)

        # 4. Translator
        with gr.TabItem("🌍 Translator"):
            text_input = gr.Textbox(label="Enter English Text")
            lang = gr.Dropdown(choices=["te", "hi", "ta", "bn", "kn", "gu", "ur"], label="Target Language")
            translated = gr.Textbox(label="Translated Text")
            translate_button = gr.Button("Translate")
            translate_button.click(fn=translate_text, inputs=[text_input, lang], outputs=translated)

        # 5. Plagiarism Checker
        with gr.TabItem("πŸ•΅οΈ Plagiarism Checker"):
            with gr.Row():
                plag_input1 = gr.Textbox(label="Text 1")
                plag_input2 = gr.Textbox(label="Text 2")
            plag_output = gr.Textbox(label="Plagiarism Result")
            plag_btn = gr.Button("Check")
            plag_btn.click(fn=check_plagiarism, inputs=[plag_input1, plag_input2], outputs=plag_output)

        # 6. Weakness Analyzer
        with gr.TabItem("πŸ“‰ Weakness Analyzer"):
            weakness_file = gr.File(label="Upload Quiz Scores CSV")
            weakness_result = gr.Textbox(label="Analysis Result")
            weakness_btn = gr.Button("Analyze")
            weakness_btn.click(fn=analyze_weakness, inputs=weakness_file, outputs=weakness_result)

        # 7. Engagement Predictor
        with gr.TabItem("πŸ“Š Engagement Predictor"):
            engagement_file = gr.File(label="Upload Student Log CSV")
            engagement_output = gr.Textbox(label="Prediction Report")
            engagement_btn = gr.Button("Predict Engagement")
            engagement_btn.click(fn=predict_engagement, inputs=engagement_file, outputs=engagement_output)

        # 8. Badge Generator
        with gr.TabItem("πŸ… Badge Generator"):
            badge_file = gr.File(label="Upload Performance CSV")
            badge_output = gr.Textbox(label="Badge Report")
            badge_btn = gr.Button("Generate Badges")
            badge_btn.click(fn=assign_badges, inputs=badge_file, outputs=badge_output)


# πŸ” Launch
demo.launch()