igortech commited on
Commit
fa0fde1
·
verified ·
1 Parent(s): c5b594f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +6 -4
app.py CHANGED
@@ -1,25 +1,27 @@
 
 
1
  import gradio as gr
2
  from transformers import pipeline
3
 
4
  generator = pipeline("text-generation", model="microsoft/DialoGPT-small")
5
 
6
  def chat_fn(message, history=None):
7
- print(f"User message: {message}")
8
  if history is None:
9
  history = []
10
  conversation = ""
11
  for user_msg, bot_msg in history:
12
  conversation += f"User: {user_msg}\nBot: {bot_msg}\n"
13
  conversation += f"User: {message}\nBot:"
14
- print(f"Built conversation prompt:\n{conversation}")
15
 
16
  try:
17
  response = generator(conversation, max_length=200, pad_token_id=50256)
18
  bot_reply = response[0]['generated_text'].split("Bot:")[-1].strip()
19
- print(f"Bot reply: {bot_reply}")
20
  except Exception as e:
21
  bot_reply = f"Error generating response: {e}"
22
- print(f"Error: {e}")
23
 
24
  history.append((message, bot_reply))
25
  return bot_reply, history
 
1
+ import logging
2
+ logging.basicConfig(filename="debug.log", level=logging.DEBUG, format='%(asctime)s %(message)s')
3
  import gradio as gr
4
  from transformers import pipeline
5
 
6
  generator = pipeline("text-generation", model="microsoft/DialoGPT-small")
7
 
8
  def chat_fn(message, history=None):
9
+ logging.debug(f"User message: {message}")
10
  if history is None:
11
  history = []
12
  conversation = ""
13
  for user_msg, bot_msg in history:
14
  conversation += f"User: {user_msg}\nBot: {bot_msg}\n"
15
  conversation += f"User: {message}\nBot:"
16
+ logging.debug(f"Built conversation prompt:\n{conversation}")
17
 
18
  try:
19
  response = generator(conversation, max_length=200, pad_token_id=50256)
20
  bot_reply = response[0]['generated_text'].split("Bot:")[-1].strip()
21
+ logging.debug(f"Bot reply: {bot_reply}")
22
  except Exception as e:
23
  bot_reply = f"Error generating response: {e}"
24
+ logging.debug(f"Error: {e}")
25
 
26
  history.append((message, bot_reply))
27
  return bot_reply, history