Trigger82 commited on
Commit
222be4e
Β·
verified Β·
1 Parent(s): 74d6030

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +28 -21
app.py CHANGED
@@ -2,42 +2,49 @@ from transformers import AutoModelForSeq2SeqLM, AutoTokenizer
2
  import gradio as gr
3
 
4
  model_id = "google/flan-t5-small"
5
-
6
  tokenizer = AutoTokenizer.from_pretrained(model_id)
7
  model = AutoModelForSeq2SeqLM.from_pretrained(model_id)
8
 
9
- system_prompt = "You are 𝕴 𝖆𝖒 π–π–Žπ–’ β€” a chill, emotionally smart, witty AI friend who talks like a real person. Be smooth, real, and clever.\n"
 
 
 
 
 
10
 
11
  def chat(history, message):
 
12
  history = history or []
13
- prompt = system_prompt
14
- for user, bot in history:
15
- prompt += f"User: {user}\nAI: {bot}\n"
16
- prompt += f"User: {message}\nAI:"
17
 
18
- input_ids = tokenizer(prompt, return_tensors="pt").input_ids
 
 
 
 
 
 
 
 
19
  outputs = model.generate(
20
- input_ids,
21
- max_new_tokens=100,
22
  do_sample=True,
23
- temperature=0.9,
24
- top_p=0.95,
25
- num_return_sequences=1
26
  )
 
27
 
28
- decoded = tokenizer.decode(outputs[0], skip_special_tokens=True)
29
- reply = decoded.split("AI:")[-1].strip()
30
-
31
- history.append((message, reply))
32
- if len(history) > 5:
33
- history = history[-5:]
34
  return history, history
35
 
36
  iface = gr.Interface(
37
  fn=chat,
38
- inputs=[gr.State(), gr.Textbox(placeholder="Talk to 𝕴 𝖆𝖒 π–π–Žπ–’...")],
39
- outputs=[gr.State(), gr.Chatbot(label="𝕴 𝖆𝖒 π–π–Žπ–’ AI Chat")],
40
- title="𝕴 𝖆𝖒 π–π–Žπ–’ - Fast AI Friend",
 
41
  allow_flagging="never",
42
  theme="default"
43
  )
 
2
  import gradio as gr
3
 
4
  model_id = "google/flan-t5-small"
 
5
  tokenizer = AutoTokenizer.from_pretrained(model_id)
6
  model = AutoModelForSeq2SeqLM.from_pretrained(model_id)
7
 
8
+ # System tone
9
+ system_prompt = (
10
+ "You are 𝕴 𝖆𝖒 π–π–Žπ–’ β€” a fun, chill, confident, emotionally tuned AI created by 𝕴 𝖆𝖒 π–π–Žπ–’.\n"
11
+ "You speak like a real friend β€” warm, clever, witty when needed, always grounded.\n"
12
+ "Avoid robotic responses. Don't repeat the question unless it adds vibe.\n\n"
13
+ )
14
 
15
  def chat(history, message):
16
+ # Keep history short and vibe-rich
17
  history = history or []
18
+ history.append(("User", message))
 
 
 
19
 
20
+ # Build conversation prompt with last 5 exchanges
21
+ convo = system_prompt
22
+ for role, text in history[-5:]:
23
+ prefix = "User:" if role == "User" else "AI:"
24
+ convo += f"{prefix} {text}\n"
25
+ convo += "AI:"
26
+
27
+ # Generate response
28
+ inputs = tokenizer(convo, return_tensors="pt")
29
  outputs = model.generate(
30
+ **inputs,
31
+ max_new_tokens=80,
32
  do_sample=True,
33
+ temperature=0.75,
34
+ top_p=0.9,
35
+ pad_token_id=tokenizer.eos_token_id
36
  )
37
+ reply = tokenizer.decode(outputs[0], skip_special_tokens=True).split("AI:")[-1].strip()
38
 
39
+ history.append(("AI", reply))
 
 
 
 
 
40
  return history, history
41
 
42
  iface = gr.Interface(
43
  fn=chat,
44
+ inputs=[gr.State(), gr.Textbox(show_label=False, placeholder="Talk to 𝕴 𝖆𝖒 π–π–Žπ–’...")],
45
+ outputs=[gr.State(), gr.Chatbot(label="𝕴 𝖆𝖒 π–π–Žπ–’")],
46
+ title="𝕴 𝖆𝖒 π–π–Žπ–’ β€” Chill AI Chatbot",
47
+ description="Realistic, smooth-talking AI made by 𝕴 𝖆𝖒 π–π–Žπ–’. Instant replies. No delays. No API. Pure vibe.",
48
  allow_flagging="never",
49
  theme="default"
50
  )