Teotonix commited on
Commit
d69a7a4
·
verified ·
1 Parent(s): 938f40b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +19 -2
app.py CHANGED
@@ -1,14 +1,31 @@
1
  import gradio as gr
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2
 
3
  def chat_fn(message, history):
4
  if history is None:
5
  history = []
 
6
  history.append({"role": "user", "content": message})
7
- history.append({"role": "assistant", "content": "AI: " + message})
 
 
8
  return history
9
 
10
  with gr.Blocks() as demo:
11
- gr.Markdown("## Maind.ai 🤖")
12
  chatbot = gr.Chatbot(value=[])
13
  msg = gr.Textbox(placeholder="Sor...")
14
  msg.submit(chat_fn, [msg, chatbot], chatbot)
 
1
  import gradio as gr
2
+ import requests
3
+ import os
4
+
5
+ HF_TOKEN = os.getenv("HF_TOKEN")
6
+ API_URL = "https://api-inference.huggingface.co/models/mistralai/Mistral-7B-Instruct-v0.2"
7
+ HEADERS = {"Authorization": f"Bearer {HF_TOKEN}"}
8
+
9
+ def query_mistral(prompt):
10
+ payload = {
11
+ "inputs": prompt,
12
+ "parameters": {"max_new_tokens": 300}
13
+ }
14
+ r = requests.post(API_URL, headers=HEADERS, json=payload)
15
+ return r.json()[0]["generated_text"]
16
 
17
  def chat_fn(message, history):
18
  if history is None:
19
  history = []
20
+
21
  history.append({"role": "user", "content": message})
22
+ reply = query_mistral(message)
23
+ history.append({"role": "assistant", "content": reply})
24
+
25
  return history
26
 
27
  with gr.Blocks() as demo:
28
+ gr.Markdown("## Maind.ai 🤖 (Mistral)")
29
  chatbot = gr.Chatbot(value=[])
30
  msg = gr.Textbox(placeholder="Sor...")
31
  msg.submit(chat_fn, [msg, chatbot], chatbot)