File size: 2,329 Bytes
0f5e2f6
3dc8cab
0f5e2f6
2ed43b0
0f5e2f6
294d5f5
0f5e2f6
294d5f5
 
 
0f5e2f6
 
7a1deb2
0f5e2f6
 
 
 
 
 
2513496
0f5e2f6
2ed43b0
0f5e2f6
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2513496
0f5e2f6
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
import os
import gradio as gr
from transformers import pipeline
from PIL import Image
import pytesseract

# Install tesseract-ocr if not available (for HF Spaces or Colab)
if not os.path.exists("/usr/bin/tesseract"):
    os.system("apt-get update && apt-get install -y tesseract-ocr")

# Load chatbot
generator = pipeline("text-generation", model="EleutherAI/gpt-neo-125M")

def chat_response(message, history=[]):
    prompt = f"Human: {message}\nAI:"
    result = generator(prompt, max_length=100, do_sample=True, temperature=0.7)[0]['generated_text']
    reply = result.split("AI:")[-1].strip()
    history.append((message, reply))
    return history, history

def solve_assignment(image):
    text = pytesseract.image_to_string(image)
    response = generator(f"Solve this problem: {text}", max_length=100, do_sample=True)[0]['generated_text']
    return f"๐Ÿง  Extracted Text:\n{text}\n\n๐Ÿ“˜ Solution:\n{response}"

def download_notes():
    content = "Here is your custom downloadable content.\nStudy hard and succeed!"
    with open("notes.txt", "w") as f:
        f.write(content)
    return "notes.txt"

def quiz_game():
    question = "What is 5 + 7?"
    return question, "12"

# UI Layout
with gr.Blocks(title="Leo9 AI Tutor") as demo:
    gr.Markdown("## ๐Ÿ‘‹ Welcome to Leo9 AI โ€” Your Smart Tutor")
    chatbot = gr.Chatbot()
    msg = gr.Textbox(label="Ask me anything in any language")
    clear = gr.Button("Clear")

    msg.submit(chat_response, [msg, chatbot], [chatbot, chatbot])
    clear.click(lambda: None, None, chatbot)

    gr.Markdown("---")
    gr.Markdown("### ๐Ÿ“ธ Upload Homework for Solving")
    image_input = gr.Image(type="pil", label="Upload assignment image")
    image_output = gr.Textbox(label="AI Solution")
    image_input.change(solve_assignment, inputs=image_input, outputs=image_output)

    gr.Markdown("---")
    gr.Markdown("### ๐ŸŽฎ Gamified Quiz (Example)")
    quiz_btn = gr.Button("Get a Quiz Question")
    quiz_q = gr.Textbox(label="Quiz Question")
    quiz_a = gr.Textbox(label="Answer")
    quiz_btn.click(quiz_game, outputs=[quiz_q, quiz_a])

    gr.Markdown("---")
    gr.Markdown("### ๐Ÿ“ฅ Download Learning Notes")
    dl_btn = gr.Button("Download Notes")
    file_output = gr.File()
    dl_btn.click(download_notes, outputs=file_output)

# Launch app
demo.launch()