File size: 847 Bytes
9a30e96 cc56034 4949764 9a30e96 cc56034 4949764 0b6fdc8 4949764 0b6fdc8 e9c4519 0b6fdc8 e9c4519 cc56034 0b6fdc8 4949764 e9c4519 4949764 0b6fdc8 4949764 4aff8cb | 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 | import gradio as gr
import os
import requests
hf_token = os.getenv("HF_TOKEN")
api_url = "https://api-inference.huggingface.co/models/SARAL-Influencer-OS/comment_analyser"
headers = {"Authorization": f"Bearer {hf_token}"} if hf_token else {}
def predict_comment(comment):
data = {"inputs": comment}
response = requests.post(api_url, headers=headers, json=data)
response.raise_for_status() # Will raise an error for bad status codes
output = response.json()
label_map = {
"LABEL_0": "Buying Intent",
"LABEL_1": "Neutral Intent",
"LABEL_2": "Negative Intent",
}
remapped_output = {label_map[item['label']]: item['score'] for item in output[0]}
return remapped_output
iface = gr.Interface(
fn=predict_comment,
inputs="text",
outputs="label"
)
iface.launch()
|