File size: 1,326 Bytes
d68d255
dc9ee59
 
5b26676
4a1a356
8203141
8def2c4
174427d
a7787d7
fb0c55e
d68d255
dc9ee59
e9eafb5
 
 
 
 
 
 
 
dc9ee59
e9eafb5
5b26676
 
 
 
0d3b314
238ae25
01cf484
 
238ae25
0d3b314
238ae25
8203141
0a182f6
12f8b4e
 
e9eafb5
d68d255
cb4ec51
d68d255
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
35
36
37
38
39
40
41
42
import gradio as gr
import json
import requests
from transformers import pipeline
headers = {"Authorization": f"Bearer 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"}
API_URL = "https://api-inference.huggingface.co/models/facebook/bart-large-mnli"
#API_URL = "https://api-inference.huggingface.co/models/microsoft/DialoGPT-large"
#API_URL = "https://api-inference.huggingface.co/models/deepset/roberta-base-squad2"
#API_URL = "https://api-inference.huggingface.co/models/bert-large-uncased-whole-word-masking-finetuned-squad"


def query(payload):
    #data = json.dumps(payload)
    """
    data = {
        "inputs": {
            "past_user_inputs": ["Which movie is the best ?"],
            "generated_responses": ["It's Die Hard for sure."],
            "text": "Can you explain why ?",
        },
    }
    """
    
    classifier = pipeline("zero-shot-classification", model="facebook/bart-large-mnli")
    

    data = {
    	"inputs": {
    		"question": payload,
    		#"context": "My name is Clara and I live in Berkeley."
    	},
    }
    
    response = requests.request("POST", API_URL, headers=headers, data=json.dumps(data))
    response_txt = json.loads(response.content.decode("utf-8"))
    print(response_txt)
    return response_txt


iface = gr.Interface(fn=query, inputs="text", outputs="text")
iface.launch()