Update app.py
Browse files1234567891011121314151617181920212223242526272829import logginglogging.basicConfig(filename="debug.log", level=logging.DEBUG, format='%(asctime)s %(message)s')import gradio as grfrom transformers import pipelinegenerator = pipeline("text-generation", model="microsoft/DialoGPT-small")def chat_fn(message, history=None):logging.debug(f"User message: {message}")if history is None:history = []conversation = ""for user_msg, bot_msg in history:conversation += f"User: {user_msg}\nBot: {bot_msg}\n"conversation += f"User: {message}\nBot:"logging.debug(f"Built conversation prompt:\n{conversation}")try:response = generator(conversation, max_length=200, pad_token_id=50256)bot_reply = response[0]['generated_text'].split("Bot:")[-1].strip()logging.debug(f"Bot reply: {bot_reply}")except Exception as e:bot_reply = f"Error generating response: {e}"logging.debug(f"Error: {e}")history.append((message, bot_reply))return bot_reply, historygr.ChatInterface(fn=chat_fn).launch()12345678910111213141516171819202122232425262728293031import logginglogging.basicConfig(filename="debug.log", level=logging.DEBUG, format='%(asctime)s %(message)s')import gradio as grfrom transformers import pipelinegenerator = pipeline("text-generation", model="microsoft/DialoGPT-small")def chat_fn(message, history=None):try:logging.debug(f"User message: {message}")if history is None:history = []conversation = ""for user_msg, bot_msg in history:conversation += f"User: {user_msg}\nBot: {bot_msg}\n"conversation += f"User: {message}\nBot:"logging.debug(f"Prompt:\n{conversation}")response = generator(conversation, max_length=200, pad_token_id=50256)bot_reply = response[0]['generated_text'].split("Bot:")[-1].strip()logging.debug(f"Bot reply: {bot_reply}")history.append((message, bot_reply))return bot_reply, historyexcept Exception as e:logging.error(f"Exception in chat_fn: {e}", exc_info=True)return f"Oops, something went wrong: {e}", history or []gr.ChatInterface(fn=chat_fn).launch()
app.py+16-14