Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,15 +1,20 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
-
from transformers import
|
| 3 |
|
| 4 |
# Load pre-trained model and tokenizer
|
| 5 |
-
model_name = "
|
| 6 |
-
tokenizer =
|
| 7 |
-
model =
|
| 8 |
|
| 9 |
def generate_response(input_text, chat_history=[]):
|
| 10 |
-
|
| 11 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 12 |
response = tokenizer.decode(reply_ids[0], skip_special_tokens=True)
|
|
|
|
| 13 |
chat_history.append((input_text, response))
|
| 14 |
return chat_history
|
| 15 |
|
|
@@ -39,7 +44,7 @@ body {
|
|
| 39 |
|
| 40 |
# Create the Gradio interface
|
| 41 |
with gr.Blocks(css=custom_css) as demo:
|
| 42 |
-
gr.Markdown("# Chat with
|
| 43 |
chatbot_ui = gr.Chatbot(label="Chatbot")
|
| 44 |
input_box = gr.Textbox(show_label=False, placeholder="Type a message...")
|
| 45 |
chat_history = gr.State([])
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
+
from transformers import AutoTokenizer, AutoModelForCausalLM
|
| 3 |
|
| 4 |
# Load pre-trained model and tokenizer
|
| 5 |
+
model_name = "EleutherAI/gpt-neo-2.7B"
|
| 6 |
+
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
| 7 |
+
model = AutoModelForCausalLM.from_pretrained(model_name)
|
| 8 |
|
| 9 |
def generate_response(input_text, chat_history=[]):
|
| 10 |
+
# Combine chat history into a single string
|
| 11 |
+
conversation = " ".join(chat_history + [input_text])
|
| 12 |
+
inputs = tokenizer.encode(conversation, return_tensors="pt")
|
| 13 |
+
|
| 14 |
+
# Generate a response
|
| 15 |
+
reply_ids = model.generate(inputs, max_length=256, pad_token_id=tokenizer.eos_token_id)
|
| 16 |
response = tokenizer.decode(reply_ids[0], skip_special_tokens=True)
|
| 17 |
+
|
| 18 |
chat_history.append((input_text, response))
|
| 19 |
return chat_history
|
| 20 |
|
|
|
|
| 44 |
|
| 45 |
# Create the Gradio interface
|
| 46 |
with gr.Blocks(css=custom_css) as demo:
|
| 47 |
+
gr.Markdown("# Chat with GPT-Neo 2.7B")
|
| 48 |
chatbot_ui = gr.Chatbot(label="Chatbot")
|
| 49 |
input_box = gr.Textbox(show_label=False, placeholder="Type a message...")
|
| 50 |
chat_history = gr.State([])
|