Spaces:
Runtime error
Runtime error
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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(fn=chat_with_mistral, inputs=gr.Textbox(lines=2, placeholder="Ask an immigration question..."),
|
| 19 |
+
outputs="text", title="🛂 Mistral 7B Immigration Chatbot",
|
| 20 |
+
description="Ask questions about immigration and work visas.")
|
| 21 |
+
|
| 22 |
+
# Launch ap
|