swapnasg commited on
Commit
fe5503a
·
verified ·
1 Parent(s): d170fb3

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +18 -4
app.py CHANGED
@@ -1,7 +1,21 @@
1
  import gradio as gr
 
2
 
3
- def greet(name):
4
- return "Hello " + name + "!!"
5
 
6
- demo = gr.Interface(fn=greet, inputs="text", outputs="text")
7
- demo.launch()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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()