itsMaaz commited on
Commit
45ae5ac
·
verified ·
1 Parent(s): 098f5e5

Delete main.py

Browse files
Files changed (1) hide show
  1. main.py +0 -44
main.py DELETED
@@ -1,44 +0,0 @@
1
- import gradio as gr
2
- from transformers import AutoModelForCausalLM, AutoTokenizer
3
- import torch
4
-
5
- # Small public model, reliable
6
- MODEL_NAME = "facebook/opt-125m"
7
-
8
- tokenizer = AutoTokenizer.from_pretrained(MODEL_NAME)
9
- model = AutoModelForCausalLM.from_pretrained(MODEL_NAME).to("cpu")
10
-
11
- history = []
12
-
13
- def chat_with_airi(user_msg):
14
- global history
15
- prompt = ""
16
- for u, a in history[-5:]:
17
- prompt += f"User: {u}\nAiri: {a}\n"
18
- prompt += f"User: {user_msg}\nAiri:"
19
-
20
- inputs = tokenizer(prompt, return_tensors="pt").to("cpu")
21
- with torch.no_grad():
22
- output = model.generate(
23
- **inputs,
24
- max_new_tokens=60,
25
- do_sample=True,
26
- top_p=0.9,
27
- temperature=0.8,
28
- pad_token_id=tokenizer.eos_token_id
29
- )
30
- reply = tokenizer.decode(output[0], skip_special_tokens=True)
31
- reply = reply.split("Airi:", 1)[-1].strip()
32
-
33
- history.append([user_msg, reply])
34
- return history, ""
35
-
36
- with gr.Blocks() as demo:
37
- gr.HTML("<h2 style='text-align:center'>Airi — Mini Chat AI</h2>")
38
- gr.HTML("<p style='text-align:center;color:#666;'>Small, Fast & Public Model</p>")
39
-
40
- chat = gr.Chatbot()
41
- msg = gr.Textbox(label="Talk to Airi…", placeholder="Write here…")
42
- msg.submit(chat_with_airi, msg, [chat, msg])
43
-
44
- demo.launch()