Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -5,11 +5,13 @@ import torch
|
|
| 5 |
# Load the TinyLlama model
|
| 6 |
model_name = "TinyLlama/TinyLlama-1.1B-Chat-v1.0"
|
| 7 |
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
| 8 |
-
|
|
|
|
|
|
|
| 9 |
|
| 10 |
# Define chatbot function
|
| 11 |
def chat_with_tinyllama(user_input):
|
| 12 |
-
inputs = tokenizer(user_input, return_tensors="pt").to("
|
| 13 |
outputs = model.generate(**inputs, max_new_tokens=200, do_sample=True, temperature=0.7, top_p=0.9, repetition_penalty=1.2)
|
| 14 |
response = tokenizer.decode(outputs[0], skip_special_tokens=True)
|
| 15 |
return response
|
|
@@ -17,10 +19,10 @@ def chat_with_tinyllama(user_input):
|
|
| 17 |
# Create Gradio UI
|
| 18 |
chatbot = gr.Interface(
|
| 19 |
fn=chat_with_tinyllama,
|
| 20 |
-
inputs=gr.Textbox(lines=2, placeholder="Ask
|
| 21 |
outputs="text",
|
| 22 |
title="🤖 TinyLlama Chatbot",
|
| 23 |
-
description="A chatbot powered by TinyLlama
|
| 24 |
)
|
| 25 |
|
| 26 |
# Launch app
|
|
|
|
| 5 |
# Load the TinyLlama model
|
| 6 |
model_name = "TinyLlama/TinyLlama-1.1B-Chat-v1.0"
|
| 7 |
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
| 8 |
+
|
| 9 |
+
# Force the model to run on CPU instead of GPU (CUDA)
|
| 10 |
+
model = AutoModelForCausalLM.from_pretrained(model_name, device_map="cpu")
|
| 11 |
|
| 12 |
# Define chatbot function
|
| 13 |
def chat_with_tinyllama(user_input):
|
| 14 |
+
inputs = tokenizer(user_input, return_tensors="pt").to("cpu") # Ensure it runs on CPU
|
| 15 |
outputs = model.generate(**inputs, max_new_tokens=200, do_sample=True, temperature=0.7, top_p=0.9, repetition_penalty=1.2)
|
| 16 |
response = tokenizer.decode(outputs[0], skip_special_tokens=True)
|
| 17 |
return response
|
|
|
|
| 19 |
# Create Gradio UI
|
| 20 |
chatbot = gr.Interface(
|
| 21 |
fn=chat_with_tinyllama,
|
| 22 |
+
inputs=gr.Textbox(lines=2, placeholder="Ask me anything..."),
|
| 23 |
outputs="text",
|
| 24 |
title="🤖 TinyLlama Chatbot",
|
| 25 |
+
description="A chatbot powered by TinyLlama-1.1B-Chat-v1.0. Ask any question!"
|
| 26 |
)
|
| 27 |
|
| 28 |
# Launch app
|