Update app.py
Browse files
app.py
CHANGED
|
@@ -1,10 +1,11 @@
|
|
| 1 |
|
| 2 |
-
model_name = 'redael/model_udc'
|
| 3 |
import os
|
| 4 |
import gradio as gr
|
| 5 |
from transformers import AutoModelForCausalLM, AutoTokenizer
|
| 6 |
import torch
|
| 7 |
|
|
|
|
|
|
|
| 8 |
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
| 9 |
model = AutoModelForCausalLM.from_pretrained(model_name)
|
| 10 |
|
|
@@ -41,17 +42,16 @@ def generate_response(message, history, system_message, max_tokens, temperature,
|
|
| 41 |
)
|
| 42 |
response = tokenizer.decode(outputs[0], skip_special_tokens=True)
|
| 43 |
|
| 44 |
-
#
|
| 45 |
response = response.split("Assistant:")[-1].strip()
|
| 46 |
response_lines = response.split('\n')
|
| 47 |
clean_response = []
|
| 48 |
for line in response_lines:
|
| 49 |
if "User:" not in line and "Assistant:" not in line:
|
| 50 |
clean_response.append(line)
|
| 51 |
-
response = ' '.join(clean_response)
|
| 52 |
|
| 53 |
-
|
| 54 |
-
return history, history
|
| 55 |
|
| 56 |
# Create the Gradio chat interface
|
| 57 |
demo = gr.ChatInterface(
|
|
|
|
| 1 |
|
|
|
|
| 2 |
import os
|
| 3 |
import gradio as gr
|
| 4 |
from transformers import AutoModelForCausalLM, AutoTokenizer
|
| 5 |
import torch
|
| 6 |
|
| 7 |
+
# Load your model and tokenizer from Hugging Face
|
| 8 |
+
model_name = 'redael/model_udc'
|
| 9 |
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
| 10 |
model = AutoModelForCausalLM.from_pretrained(model_name)
|
| 11 |
|
|
|
|
| 42 |
)
|
| 43 |
response = tokenizer.decode(outputs[0], skip_special_tokens=True)
|
| 44 |
|
| 45 |
+
# Clean up the response
|
| 46 |
response = response.split("Assistant:")[-1].strip()
|
| 47 |
response_lines = response.split('\n')
|
| 48 |
clean_response = []
|
| 49 |
for line in response_lines:
|
| 50 |
if "User:" not in line and "Assistant:" not in line:
|
| 51 |
clean_response.append(line)
|
| 52 |
+
response = ' '.join(clean_response)
|
| 53 |
|
| 54 |
+
return [(message, response)]
|
|
|
|
| 55 |
|
| 56 |
# Create the Gradio chat interface
|
| 57 |
demo = gr.ChatInterface(
|