Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -1,7 +1,21 @@
|
|
1 |
import gradio as gr
|
|
|
2 |
|
3 |
-
|
4 |
-
|
5 |
|
6 |
-
|
7 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
import gradio as gr
|
2 |
+
from transformers import AutoTokenizer, AutoModelForCausalLM, pipeline
|
3 |
|
4 |
+
# Load Mistral 7B instruct model
|
5 |
+
model_id = "mistralai/Mistral-7B-Instruct-v0.1"
|
6 |
|
7 |
+
tokenizer = AutoTokenizer.from_pretrained(model_id)
|
8 |
+
model = AutoModelForCausalLM.from_pretrained(model_id, device_map="auto")
|
9 |
+
|
10 |
+
pipe = pipeline("text-generation", model=model, tokenizer=tokenizer)
|
11 |
+
|
12 |
+
def chat_with_expert(message, history):
|
13 |
+
prompt = f"<s>[INST] You are an expert assistant. Answer with clarity and depth.\n{message} [/INST]"
|
14 |
+
response = pipe(prompt, max_new_tokens=256, do_sample=True, temperature=0.7)[0]['generated_text']
|
15 |
+
answer = response.split('[/INST]')[-1].strip()
|
16 |
+
history.append((message, answer))
|
17 |
+
return history, history
|
18 |
+
|
19 |
+
chatbot = gr.ChatInterface(fn=chat_with_expert, title="Expert Chat Assistant")
|
20 |
+
|
21 |
+
chatbot.launch()
|