Spaces:
Runtime error

markshep68 commited on
Commit
8d34fa1
·
verified ·
1 Parent(s): cbf9bc2

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +22 -1
app.py CHANGED
@@ -1,4 +1,13 @@
1
- # Debugging version of chatbot function
 
 
 
 
 
 
 
 
 
2
  def chat_with_mistral(user_input):
3
  try:
4
  inputs = tokenizer(user_input, return_tensors="pt").to("cuda")
@@ -7,3 +16,15 @@ def chat_with_mistral(user_input):
7
  return response
8
  except Exception as e:
9
  return f"⚠️ Error: {str(e)}"
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ 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
+ tokenizer = AutoTokenizer.from_pretrained(model_name, token=True)
8
+ model = AutoModelForCausalLM.from_pretrained(model_name, device_map="auto", torch_dtype=torch.float16, token=True)
9
+
10
+ # Define chatbot function (THIS WAS MISSING)
11
  def chat_with_mistral(user_input):
12
  try:
13
  inputs = tokenizer(user_input, return_tensors="pt").to("cuda")
 
16
  return response
17
  except Exception as e:
18
  return f"⚠️ Error: {str(e)}"
19
+
20
+ # Create Gradio UI
21
+ chatbot = gr.Interface(
22
+ fn=chat_with_mistral,
23
+ inputs=gr.Textbox(lines=2, placeholder="Ask an immigration question..."),
24
+ outputs="text",
25
+ title="🛂 Mistral 7B Immigration Chatbot",
26
+ description="Ask questions about immigration and work visas."
27
+ )
28
+
29
+ # Launch app
30
+ chatbot.launch()