Spaces:
Runtime error

markshep68 commited on
Commit
82dbfbc
·
verified ·
1 Parent(s): 0a83a22

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +27 -0
app.py ADDED
@@ -0,0 +1,27 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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, use_auth_token=True)
8
+ model = AutoModelForCausalLM.from_pretrained(model_name, device_map="auto", torch_dtype=torch.float16)
9
+
10
+ # Define chatbot function
11
+ def chat_with_mistral(user_input):
12
+ inputs = tokenizer(user_input, return_tensors="pt").to("cuda")
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
16
+
17
+ # Create Gradio UI
18
+ chatbot = gr.Interface(
19
+ fn=chat_with_mistral,
20
+ inputs=gr.Textbox(lines=2, placeholder="Ask an immigration question..."),
21
+ outputs="text",
22
+ title="🛂 Mistral 7B Immigration Chatbot",
23
+ description="Ask questions about immigration and work visas."
24
+ )
25
+
26
+ # Launch app
27
+ chatbot.launch()