Spaces:
Runtime error
Runtime error
File size: 1,881 Bytes
086be27 1a03bae 086be27 a16765f 1a03bae 086be27 a16765f 086be27 a16765f 1a03bae a16765f 1a03bae a16765f 1a03bae a16765f 1a03bae 9e46d20 1a03bae 086be27 3303731 086be27 |
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 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
import gradio as gr
import requests
import os
import io
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"
API_URL4 = "https://api-inference.huggingface.co/models/runwayml/stable-diffusion-v1-5"
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)
elif (select_model=="HandWriting"):
data = open(filepath, 'rb' ).read()
response = requests.post(API_URL3, headers=headers, data=data)
else:
response = requests.post(API_URL4, headers=headers, json=mood)
if (select_model=="Sentiment"):
return str(response.json())
elif (select_model=="WhatIsThat"):
return str(response.json())
elif (select_model=="HandWriting"):
return str(response.json())
else:
return response.content
def greet(mood,select_model,image):
output = query({"inputs":mood}, select_model, image)
if (select_model=="Text2Image"):
from PIL import Image
image = Image.open(io.BytesIO(output))
else:
print (str(output))
return str(output)
iface = gr.Interface(
fn=greet, inputs=["text", gr.Radio(choices=["Sentiment", "WhatIsThat", "HandWriting","Text2Image"],value="Sentiment"),gr.Image(type="filepath")], outputs=["text","image"])
iface.launch()
|