Pgohari commited on
Commit
7aa1147
1 Parent(s): 1376f2a

create appy.py

Browse files
Files changed (1) hide show
  1. app.py +23 -0
app.py ADDED
@@ -0,0 +1,23 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # First, ensure transformers and gradio are installed
2
+ !pip install transformers gradio
3
+
4
+ import gradio as gr
5
+ from transformers import AutoModelForCausalLM, AutoTokenizer
6
+
7
+ # Load the Mistral AI model and tokenizer from Hugging Face
8
+ model_name = "mistralai/Mistral-7B"
9
+ tokenizer = AutoTokenizer.from_pretrained(model_name)
10
+ model = AutoModelForCausalLM.from_pretrained(model_name)
11
+
12
+ # Define the chatbot function
13
+ def chatbot(user_input):
14
+ inputs = tokenizer(user_input, return_tensors="pt")
15
+ outputs = model.generate(inputs['input_ids'], max_length=50)
16
+ response = tokenizer.decode(outputs[0], skip_special_tokens=True)
17
+ return response
18
+
19
+ # Set up the Gradio interface
20
+ demo = gr.Interface(fn=chatbot, inputs="text", outputs="text", title="Mistral AI Chatbot")
21
+
22
+ # Launch the app
23
+ demo.launch()