Spaces:
Sleeping
Sleeping
File size: 1,251 Bytes
37a76f2 4ab4f18 37a76f2 4ab4f18 37a76f2 4ab4f18 37a76f2 4ab4f18 37a76f2 |
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 |
import gradio as gr
import requests
import os
API_URL1 = "/static-proxy?url=https%3A%2F%2Fapi-inference.huggingface.co%2Fmodels%2Fcardiffnlp%2Ftwitter-roberta-base-sentiment%26quot%3B%3C%2Fspan%3E
API_URL2 = "/static-proxy?url=https%3A%2F%2Fapi-inference.huggingface.co%2Fmodels%2Ffacebook%2Fconvnext-xlarge-384-22k-1k%26quot%3B%3C%2Fspan%3E
API_URL3 = "/static-proxy?url=https%3A%2F%2Fapi-inference.huggingface.co%2Fmodels%2Fmicrosoft%2Ftrocr-base-handwritten%26quot%3B%3C%2Fspan%3E
bt = os.environ['HACKAITHONBEARERTOKEN']
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()
|