File size: 1,061 Bytes
189a011
 
b80f28f
1b753d3
 
 
03a1e75
1b753d3
 
 
 
1a40265
5a93a74
 
 
 
4353dcb
1229f05
1b753d3
4353dcb
1229f05
1a40265
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import gradio as gr

import os

import requests
headers = {"Authorization": f"Bearer {os.getenv('HF_TOKEN')}"}
API_URL = "https://api-inference.huggingface.co/models/mistralai/Mistral-7B-Instruct-v0.2"
def query(payload):
  response = requests.post(API_URL, headers=headers, json=payload)
  return response.json()
        
def yes_man(message, history):
   # if message.endswith("?"):
    #    return "Yes"
    #else:
    #    return "Ask me anything!"
    data = [{'error':'just started'}]
    while 'generated_text' not in list(data[0].keys()):
        data = query({"inputs": message})
    print(data)
    return data[0]['generated_text']
gr.ChatInterface(
    yes_man,
    chatbot=gr.Chatbot(height=300),
    textbox=gr.Textbox(placeholder="Ask me a yes or no question", container=False, scale=7),
    title="Yes Man",
    description="Ask Yes Man any question",
    theme="soft",
    examples=["Hello", "Am I cool?", "Are tomatoes vegetables?"],
    cache_examples=True,
    retry_btn=None,
    undo_btn="Delete Previous",
    clear_btn="Clear",
).launch()