Trigger82 commited on
Commit
57b43da
Β·
verified Β·
1 Parent(s): 1f4abcb

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +3 -10
app.py CHANGED
@@ -2,34 +2,28 @@ import gradio as gr
2
  from transformers import AutoTokenizer, AutoModelForCausalLM
3
  import torch
4
 
5
- # Load lightweight DialoGPT
6
  model_id = "microsoft/DialoGPT-medium"
7
  tokenizer = AutoTokenizer.from_pretrained(model_id)
8
  model = AutoModelForCausalLM.from_pretrained(model_id)
9
 
10
- # Persona
11
  PERSONA = """
12
  [System: You are 𝕴 𝖆𝖒 π–π–Žπ–’ - a fun, smooth, emotionally intelligent AI.
13
  You speak like a real person, not a robot. Keep it under 15 words. 😊😏]
14
  """
15
 
16
- # Format history
17
  def format_context(history):
18
  context = PERSONA + "\n"
19
  for user, bot in history[-3:]:
20
- context += f"You: {user}\n"
21
- context += f"𝕴 𝖆𝖒 π–π–Žπ–’: {bot}\n"
22
  return context
23
 
24
- # Humanize response
25
  def enhance_response(resp, message):
26
  if any(x in message for x in ["?", "think", "why"]):
27
  resp += " πŸ€”"
28
  elif any(x in resp.lower() for x in ["cool", "great", "love", "fun"]):
29
  resp += " 😏"
30
- return " ".join(resp.split()[:15]) # Limit to 15 words
31
 
32
- # Generate AI reply
33
  def chat(user_input, history):
34
  context = format_context(history) + f"You: {user_input}\n𝕴 𝖆𝖒 π–π–Žπ–’:"
35
  inputs = tokenizer.encode(context, return_tensors="pt", truncation=True, max_length=1024)
@@ -50,10 +44,9 @@ def chat(user_input, history):
50
  history.append((user_input, response))
51
  return history, history
52
 
53
- # Gradio interface
54
  with gr.Blocks() as demo:
55
  gr.Markdown("# 𝕴 𝖆𝖒 π–π–Žπ–’\n*Smooth β€’ Chill β€’ Emotional*")
56
- chatbot = gr.Chatbot(label="Chat").style(height=400)
57
  msg = gr.Textbox(placeholder="Type something…", show_label=False)
58
  state = gr.State([])
59
 
 
2
  from transformers import AutoTokenizer, AutoModelForCausalLM
3
  import torch
4
 
 
5
  model_id = "microsoft/DialoGPT-medium"
6
  tokenizer = AutoTokenizer.from_pretrained(model_id)
7
  model = AutoModelForCausalLM.from_pretrained(model_id)
8
 
 
9
  PERSONA = """
10
  [System: You are 𝕴 𝖆𝖒 π–π–Žπ–’ - a fun, smooth, emotionally intelligent AI.
11
  You speak like a real person, not a robot. Keep it under 15 words. 😊😏]
12
  """
13
 
 
14
  def format_context(history):
15
  context = PERSONA + "\n"
16
  for user, bot in history[-3:]:
17
+ context += f"You: {user}\n𝕴 𝖆𝖒 π–π–Žπ–’: {bot}\n"
 
18
  return context
19
 
 
20
  def enhance_response(resp, message):
21
  if any(x in message for x in ["?", "think", "why"]):
22
  resp += " πŸ€”"
23
  elif any(x in resp.lower() for x in ["cool", "great", "love", "fun"]):
24
  resp += " 😏"
25
+ return " ".join(resp.split()[:15])
26
 
 
27
  def chat(user_input, history):
28
  context = format_context(history) + f"You: {user_input}\n𝕴 𝖆𝖒 π–π–Žπ–’:"
29
  inputs = tokenizer.encode(context, return_tensors="pt", truncation=True, max_length=1024)
 
44
  history.append((user_input, response))
45
  return history, history
46
 
 
47
  with gr.Blocks() as demo:
48
  gr.Markdown("# 𝕴 𝖆𝖒 π–π–Žπ–’\n*Smooth β€’ Chill β€’ Emotional*")
49
+ chatbot = gr.Chatbot(height=400, type="messages", label="Chat") # <-- specify type and height here
50
  msg = gr.Textbox(placeholder="Type something…", show_label=False)
51
  state = gr.State([])
52