itsMaaz commited on
Commit
59e5368
·
verified ·
1 Parent(s): 45ae5ac

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +52 -0
app.py ADDED
@@ -0,0 +1,52 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ import gradio as gr
3
+ import torch
4
+ from transformers import AutoModelForCausalLM, AutoTokenizer
5
+
6
+ # Use your Hugging Face token from the Secrets
7
+ HF_TOKEN = os.environ.get("HF_TOKEN")
8
+
9
+ # Model (lightweight, public, works on CPU)
10
+ MODEL_NAME = "SandLogicTechnologies/Gemma-3-270m-GGUF"
11
+
12
+ # Load tokenizer and model
13
+ tokenizer = AutoTokenizer.from_pretrained(MODEL_NAME, use_auth_token=HF_TOKEN)
14
+ model = AutoModelForCausalLM.from_pretrained(MODEL_NAME, use_auth_token=HF_TOKEN).to("cpu")
15
+
16
+ history = []
17
+
18
+ def chat_with_airi(user_msg):
19
+ global history
20
+ # build simple prompt
21
+ prompt = ""
22
+ for u, a in history[-5:]:
23
+ prompt += f"User: {u}\nAiri: {a}\n"
24
+ prompt += f"User: {user_msg}\nAiri:"
25
+
26
+ inputs = tokenizer(prompt, return_tensors="pt").to("cpu")
27
+ with torch.no_grad():
28
+ output = model.generate(
29
+ **inputs,
30
+ max_new_tokens=60,
31
+ do_sample=True,
32
+ top_p=0.9,
33
+ temperature=0.8,
34
+ pad_token_id=tokenizer.eos_token_id
35
+ )
36
+
37
+ reply = tokenizer.decode(output[0], skip_special_tokens=True)
38
+ reply = reply.split("Airi:", 1)[-1].strip()
39
+
40
+ history.append([user_msg, reply])
41
+ return history, ""
42
+
43
+ # Gradio interface
44
+ with gr.Blocks() as demo:
45
+ gr.HTML("<h2 style='text-align:center'>Airi — Mini Chat AI</h2>")
46
+ gr.HTML("<p style='text-align:center;color:#666;'>Small, Fast & Public Model</p>")
47
+
48
+ chat = gr.Chatbot()
49
+ msg = gr.Textbox(label="Talk to Airi…", placeholder="Write here…")
50
+ msg.submit(chat_with_airi, msg, [chat, msg])
51
+
52
+ demo.launch()