Update app.py
Browse files
app.py
CHANGED
|
@@ -27,7 +27,7 @@ def enhance_response(resp, message):
|
|
| 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)
|
| 30 |
-
|
| 31 |
outputs = model.generate(
|
| 32 |
inputs,
|
| 33 |
max_new_tokens=50,
|
|
@@ -40,17 +40,12 @@ def chat(user_input, history):
|
|
| 40 |
full_text = tokenizer.decode(outputs[0], skip_special_tokens=True)
|
| 41 |
response = full_text.split("π΄ ππ πππ:")[-1].split("\nYou:")[0].strip()
|
| 42 |
response = enhance_response(response, user_input)
|
| 43 |
-
|
| 44 |
-
history.append((user_input, response))
|
| 45 |
-
return history # Return just the updated chat history
|
| 46 |
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
chatbot = gr.Chatbot(height=400, type="messages", label="Chat")
|
| 50 |
-
msg = gr.Textbox(placeholder="Type somethingβ¦", show_label=False)
|
| 51 |
-
state = gr.State([])
|
| 52 |
|
| 53 |
-
|
| 54 |
-
|
| 55 |
|
| 56 |
-
|
|
|
|
|
|
| 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)
|
| 30 |
+
|
| 31 |
outputs = model.generate(
|
| 32 |
inputs,
|
| 33 |
max_new_tokens=50,
|
|
|
|
| 40 |
full_text = tokenizer.decode(outputs[0], skip_special_tokens=True)
|
| 41 |
response = full_text.split("π΄ ππ πππ:")[-1].split("\nYou:")[0].strip()
|
| 42 |
response = enhance_response(response, user_input)
|
|
|
|
|
|
|
|
|
|
| 43 |
|
| 44 |
+
history.append((user_input, response))
|
| 45 |
+
return history
|
|
|
|
|
|
|
|
|
|
| 46 |
|
| 47 |
+
# Create the Gradio Interface
|
| 48 |
+
demo = gr.Interface(fn=chat, inputs=["text", "state"], outputs="state")
|
| 49 |
|
| 50 |
+
# Launch the app
|
| 51 |
+
demo.launch()
|