muhammadrazapathan commited on
Commit
e2fc7f4
Β·
verified Β·
1 Parent(s): 421367f

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +79 -0
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()