Spaces:
Runtime error
Runtime error
Fix the errors in app.py
Browse files
app.py
CHANGED
@@ -40,3 +40,53 @@ def generate_response(user_input, chat_history):
|
|
40 |
inputs.input_ids,
|
41 |
max_length=len(inputs.input_ids[0]) + max_response_length, # Limit the maximum length for context and response
|
42 |
min_length=45,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
40 |
inputs.input_ids,
|
41 |
max_length=len(inputs.input_ids[0]) + max_response_length, # Limit the maximum length for context and response
|
42 |
min_length=45,
|
43 |
+
temperature=0.7, # Slightly higher temperature for more diverse responses
|
44 |
+
top_k=30,
|
45 |
+
top_p=0.9, # Allow a bit more randomness
|
46 |
+
repetition_penalty=1.1, # Mild repetition penalty
|
47 |
+
no_repeat_ngram_size=3, # Ensure no repeated phrases
|
48 |
+
eos_token_id=tokenizer.eos_token_id,
|
49 |
+
pad_token_id=tokenizer.eos_token_id
|
50 |
+
)
|
51 |
+
|
52 |
+
response = tokenizer.decode(outputs[0], skip_special_tokens=True)
|
53 |
+
|
54 |
+
# Post-process the assistant's response
|
55 |
+
assistant_response = response.split("Assistant:")[-1].strip()
|
56 |
+
# Ensure the response ends properly by stripping incomplete sentences
|
57 |
+
assistant_response = assistant_response.split('\n')[0].strip()
|
58 |
+
|
59 |
+
# Append the interaction to the chat history
|
60 |
+
chat_history.append((user_input, assistant_response))
|
61 |
+
|
62 |
+
# Return the updated chat history
|
63 |
+
return chat_history, chat_history
|
64 |
+
|
65 |
+
def restart_chat():
|
66 |
+
return [], []
|
67 |
+
|
68 |
+
# Create Gradio Interface
|
69 |
+
with gr.Blocks() as chat_interface:
|
70 |
+
gr.Markdown("<h1><center>W.AI Chat Nikker xD</center></h1>")
|
71 |
+
chat_history = gr.State([])
|
72 |
+
with gr.Column():
|
73 |
+
chatbox = gr.Chatbot()
|
74 |
+
with gr.Row():
|
75 |
+
user_input = gr.Textbox(show_label=False, placeholder="Summon Wali Here...")
|
76 |
+
submit_button = gr.Button("Send")
|
77 |
+
restart_button = gr.Button("Restart")
|
78 |
+
|
79 |
+
submit_button.click(
|
80 |
+
generate_response,
|
81 |
+
inputs=[user_input, chat_history],
|
82 |
+
outputs=[chatbox, chat_history]
|
83 |
+
)
|
84 |
+
|
85 |
+
restart_button.click(
|
86 |
+
restart_chat,
|
87 |
+
inputs=[],
|
88 |
+
outputs=[chatbox, chat_history]
|
89 |
+
)
|
90 |
+
|
91 |
+
# Launch the Gradio interface with share=True
|
92 |
+
chat_interface.launch(share=True)
|