nageshsomayajula commited on
Commit
e5f754c
·
1 Parent(s): 77f3e83

Upload app.py

Browse files
Files changed (1) hide show
  1. app.py +30 -0
app.py ADDED
@@ -0,0 +1,30 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from transformers import AutoModelForCausalLM, AutoTokenizer
2
+ import gradio as gr
3
+ import random
4
+ import time
5
+
6
+ def call_chat(message)
7
+ model_id = "mistralai/Mixtral-8x7B-Instruct-v0.1"
8
+ tokenizer = AutoTokenizer.from_pretrained(model_id)
9
+ model = AutoModelForCausalLM.from_pretrained(model_id)
10
+ inputs = tokenizer(message, return_tensors="pt")
11
+ outputs = model.generate(**inputs, max_new_tokens=20)
12
+ return tokenizer.decode(outputs[0], skip_special_tokens=True)
13
+
14
+
15
+
16
+
17
+ with gr.Blocks() as demo:
18
+ chatbot = gr.Chatbot()
19
+ msg = gr.Textbox()
20
+ clear = gr.ClearButton([msg, chatbot])
21
+
22
+ def respond(message, chat_history):
23
+ bot_message = random.choice(["How are you?", "I love you", "I'm very hungry"])
24
+ chat_history.append((message, bot_message))
25
+ time.sleep(2)
26
+ return "", chat_history
27
+
28
+ msg.submit(call_chat, [msg, chatbot], [msg, chatbot])
29
+
30
+ demo.launch()