sentiment / app.py
Jacek Konopelski
oooo
f85e68f
import gradio as gr
import requests
import os
API_URL1 = "https://api-inference.huggingface.co/models/cardiffnlp/twitter-roberta-base-sentiment"
API_URL2 = "https://api-inference.huggingface.co/models/facebook/convnext-xlarge-384-22k-1k"
API_URL3 = "https://api-inference.huggingface.co/models/microsoft/trocr-base-handwritten"
bt = os.environ['RobertaSecret']
headers = {"Authorization": bt }
def query(mood, select_model, filepath):
print (select_model);
print (filepath);
if (select_model=="Sentiment"):
response = requests.post(API_URL1, headers=headers, json=mood)
elif (select_model=="WhatIsThat"):
data = open(filepath, 'rb' ).read()
response = requests.post(API_URL2, headers=headers, data=data)
else:
data = open(filepath, 'rb' ).read()
response = requests.post(API_URL3, headers=headers, data=data)
return str(response.json())
def greet(mood,select_model,image):
output = query({"inputs":mood}, select_model, image)
print (str(output))
return str(output)
iface = gr.Interface(
fn=greet, inputs=["text", gr.Radio(choices=["Sentiment", "WhatIsThat", "HandWriting"],value="Sentiment"),gr.Image(type="filepath")], outputs="text")
iface.launch()