SHAILJA1 commited on
Commit
c2b1871
·
verified ·
1 Parent(s): 063b1fa

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +28 -0
app.py ADDED
@@ -0,0 +1,28 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from transformers import AutoModelForCausalLM, AutoTokenizer, pipeline
3
+
4
+ # Load tokenizer and model
5
+ model_name = "mistralai/Mistral-7B-Instruct-v0.1"
6
+
7
+ # Use text-generation pipeline with model
8
+ generator = pipeline("text-generation", model=model_name, tokenizer=model_name, device_map="auto", max_new_tokens=200)
9
+
10
+ # Chat function
11
+ def chat_with_bot(message, history=[]):
12
+ # Instruction format
13
+ prompt = f"[INST] {message} [/INST]"
14
+ response = generator(prompt)[0]['generated_text'].split('[/INST]')[-1].strip()
15
+ history.append((message, response))
16
+ return history, history
17
+
18
+ # Gradio Chat Interface
19
+ chat_interface = gr.ChatInterface(
20
+ fn=chat_with_bot,
21
+ chatbot=gr.Chatbot(),
22
+ textbox=gr.Textbox(placeholder="Ask me anything...", lines=2),
23
+ title="🤖 Mistral Chatbot",
24
+ description="Free chatbot using Mistral 7B Instruct model from Hugging Face",
25
+ theme="soft"
26
+ )
27
+
28
+ chat_interface.launch()