Spaces:
Runtime error

markshep68 commited on
Commit
55d7625
·
verified ·
1 Parent(s): 4852346

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +8 -9
app.py CHANGED
@@ -2,20 +2,20 @@ import gradio as gr
2
  from transformers import AutoModelForCausalLM, AutoTokenizer
3
  import torch
4
 
5
- # Load the Mistral-7B model
6
- model_name = "mistralai/Mistral-7B-v0.1"
7
 
8
- # Set device to CPU to avoid GPU/driver errors
9
  device = "cpu"
10
 
11
  # Load tokenizer
12
- tokenizer = AutoTokenizer.from_pretrained(model_name, token=True)
13
 
14
- # Load model without quantization
15
  model = AutoModelForCausalLM.from_pretrained(model_name).to(device)
16
 
17
  # Define chatbot function
18
- def chat_with_mistral(user_input):
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=chat_with_mistral,
37
  inputs=gr.Textbox(lines=2, placeholder="Ask an immigration question..."),
38
  outputs="text",
39
- title="🛂 Mistral 7B Immigration Chatbot",
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()