Spaces:
Runtime error
Runtime error
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() | |