Spaces:
Build error
Build error
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,79 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
from transformers import AutoTokenizer, AutoModelForCausalLM, pipeline
|
| 3 |
+
import torch
|
| 4 |
+
|
| 5 |
+
# ==========================================
|
| 6 |
+
# Load Lightweight LLaMA-style Model
|
| 7 |
+
# (Works on HuggingFace Free CPU)
|
| 8 |
+
# ==========================================
|
| 9 |
+
|
| 10 |
+
model_name = "TinyLlama/TinyLlama-1.1B-Chat-v1.0"
|
| 11 |
+
|
| 12 |
+
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
| 13 |
+
|
| 14 |
+
model = AutoModelForCausalLM.from_pretrained(
|
| 15 |
+
model_name,
|
| 16 |
+
device_map="auto"
|
| 17 |
+
)
|
| 18 |
+
|
| 19 |
+
pipe = pipeline(
|
| 20 |
+
"text-generation",
|
| 21 |
+
model=model,
|
| 22 |
+
tokenizer=tokenizer,
|
| 23 |
+
max_new_tokens=256,
|
| 24 |
+
temperature=0.7,
|
| 25 |
+
do_sample=True
|
| 26 |
+
)
|
| 27 |
+
|
| 28 |
+
# ==========================================
|
| 29 |
+
# EduPredict AI Function
|
| 30 |
+
# ==========================================
|
| 31 |
+
|
| 32 |
+
def edupredict(message, history):
|
| 33 |
+
prompt = f"""
|
| 34 |
+
You are EduPredict AI β an assistant for students.
|
| 35 |
+
|
| 36 |
+
You help with:
|
| 37 |
+
β’ Study Planning
|
| 38 |
+
β’ Career Guidance
|
| 39 |
+
β’ Skill Recommendations
|
| 40 |
+
β’ Exam Preparation
|
| 41 |
+
β’ Motivation & Productivity
|
| 42 |
+
|
| 43 |
+
Student Question:
|
| 44 |
+
{message}
|
| 45 |
+
|
| 46 |
+
Give a clear, helpful answer:
|
| 47 |
+
"""
|
| 48 |
+
|
| 49 |
+
result = pipe(prompt)
|
| 50 |
+
answer = result[0]["generated_text"].replace(prompt, "").strip()
|
| 51 |
+
|
| 52 |
+
return answer
|
| 53 |
+
|
| 54 |
+
|
| 55 |
+
# ==========================================
|
| 56 |
+
# Gradio Modern Interface
|
| 57 |
+
# ==========================================
|
| 58 |
+
|
| 59 |
+
with gr.Blocks(theme=gr.themes.Soft()) as demo:
|
| 60 |
+
gr.Markdown("""
|
| 61 |
+
# π EduPredict AI
|
| 62 |
+
### Your Personal Academic Assistant
|
| 63 |
+
|
| 64 |
+
Ask anything about:
|
| 65 |
+
- π How to study
|
| 66 |
+
- π― Which career to choose
|
| 67 |
+
- π» Skills to learn
|
| 68 |
+
- π Exam preparation
|
| 69 |
+
""")
|
| 70 |
+
|
| 71 |
+
chatbot = gr.ChatInterface(
|
| 72 |
+
fn=edupredict,
|
| 73 |
+
title="EduPredict AI Chat",
|
| 74 |
+
retry_btn="π Retry",
|
| 75 |
+
undo_btn="β© Undo",
|
| 76 |
+
clear_btn="π Clear"
|
| 77 |
+
)
|
| 78 |
+
|
| 79 |
+
demo.launch()
|