igortech commited on
Commit
43705db
·
verified ·
1 Parent(s): c18c152

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +4 -12
app.py CHANGED
@@ -4,18 +4,10 @@ from transformers import pipeline
4
  generator = pipeline("text-generation", model="microsoft/DialoGPT-small")
5
 
6
  def chat_fn(message, history=None):
7
- if history is None:
8
- history = []
9
- conversation = ""
10
- for user_msg, bot_msg in history:
11
- conversation += f"User: {user_msg}\nBot: {bot_msg}\n"
12
- conversation += f"User: {message}\nBot:"
13
  try:
14
- response = generator(conversation, max_length=200, pad_token_id=50256)
15
- bot_reply = response[0]['generated_text'].split("Bot:")[-1].strip()
 
16
  except Exception as e:
17
- bot_reply = f"Error: {e}"
18
- history.append((message, bot_reply))
19
- return bot_reply, history
20
-
21
  gr.ChatInterface(fn=chat_fn).launch()
 
4
  generator = pipeline("text-generation", model="microsoft/DialoGPT-small")
5
 
6
  def chat_fn(message, history=None):
 
 
 
 
 
 
7
  try:
8
+ response = generator(message, max_length=100, pad_token_id=50256)
9
+ bot_reply = response[0]['generated_text'].strip()
10
+ return bot_reply, history or []
11
  except Exception as e:
12
+ return f"Error: {e}", history or []
 
 
 
13
  gr.ChatInterface(fn=chat_fn).launch()