Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -2,20 +2,20 @@ import gradio as gr
|
|
| 2 |
from transformers import AutoModelForCausalLM, AutoTokenizer
|
| 3 |
import torch
|
| 4 |
|
| 5 |
-
# Load
|
| 6 |
-
model_name = "
|
| 7 |
|
| 8 |
-
# Set device to CPU to avoid
|
| 9 |
device = "cpu"
|
| 10 |
|
| 11 |
# Load tokenizer
|
| 12 |
-
tokenizer = AutoTokenizer.from_pretrained(model_name
|
| 13 |
|
| 14 |
-
# Load model
|
| 15 |
model = AutoModelForCausalLM.from_pretrained(model_name).to(device)
|
| 16 |
|
| 17 |
# Define chatbot function
|
| 18 |
-
def
|
| 19 |
try:
|
| 20 |
inputs = tokenizer(user_input, return_tensors="pt").to(device)
|
| 21 |
outputs = model.generate(
|
|
@@ -33,13 +33,12 @@ def chat_with_mistral(user_input):
|
|
| 33 |
|
| 34 |
# Create Gradio UI
|
| 35 |
chatbot = gr.Interface(
|
| 36 |
-
fn=
|
| 37 |
inputs=gr.Textbox(lines=2, placeholder="Ask an immigration question..."),
|
| 38 |
outputs="text",
|
| 39 |
-
title="🛂
|
| 40 |
description="Ask questions about immigration and work visas."
|
| 41 |
)
|
| 42 |
|
| 43 |
# Launch app
|
| 44 |
chatbot.launch()
|
| 45 |
-
|
|
|
|
| 2 |
from transformers import AutoModelForCausalLM, AutoTokenizer
|
| 3 |
import torch
|
| 4 |
|
| 5 |
+
# Load a smaller model (TinyLlama-1.1B)
|
| 6 |
+
model_name = "TinyLlama/TinyLlama-1.1B" # Change model here
|
| 7 |
|
| 8 |
+
# Set device to CPU to avoid memory issues
|
| 9 |
device = "cpu"
|
| 10 |
|
| 11 |
# Load tokenizer
|
| 12 |
+
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
| 13 |
|
| 14 |
+
# Load model
|
| 15 |
model = AutoModelForCausalLM.from_pretrained(model_name).to(device)
|
| 16 |
|
| 17 |
# Define chatbot function
|
| 18 |
+
def chat_with_model(user_input):
|
| 19 |
try:
|
| 20 |
inputs = tokenizer(user_input, return_tensors="pt").to(device)
|
| 21 |
outputs = model.generate(
|
|
|
|
| 33 |
|
| 34 |
# Create Gradio UI
|
| 35 |
chatbot = gr.Interface(
|
| 36 |
+
fn=chat_with_model,
|
| 37 |
inputs=gr.Textbox(lines=2, placeholder="Ask an immigration question..."),
|
| 38 |
outputs="text",
|
| 39 |
+
title="🛂 Immigration Chatbot",
|
| 40 |
description="Ask questions about immigration and work visas."
|
| 41 |
)
|
| 42 |
|
| 43 |
# Launch app
|
| 44 |
chatbot.launch()
|
|
|