Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -3,20 +3,34 @@ import gradio as gr
|
|
| 3 |
import requests
|
| 4 |
import os
|
| 5 |
|
| 6 |
-
|
|
|
|
|
|
|
| 7 |
|
| 8 |
bt = os.environ['HACKAITHONBEARERTOKEN']
|
| 9 |
headers = {"Authorization": bt }
|
| 10 |
|
| 11 |
-
def query(
|
| 12 |
-
response = requests.post(API_URL, headers=headers, json=data)
|
| 13 |
-
return "V2"+str(response.json())
|
| 14 |
|
| 15 |
-
|
| 16 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 17 |
print (str(output))
|
| 18 |
return str(output)
|
| 19 |
|
| 20 |
iface = gr.Interface(
|
| 21 |
-
fn=greet, inputs=["text"
|
| 22 |
iface.launch()
|
|
|
|
| 3 |
import requests
|
| 4 |
import os
|
| 5 |
|
| 6 |
+
API_URL1 = "https://api-inference.huggingface.co/models/cardiffnlp/twitter-roberta-base-sentiment"
|
| 7 |
+
API_URL2 = "https://api-inference.huggingface.co/models/facebook/convnext-xlarge-384-22k-1k"
|
| 8 |
+
API_URL3 = "https://api-inference.huggingface.co/models/microsoft/trocr-base-handwritten"
|
| 9 |
|
| 10 |
bt = os.environ['HACKAITHONBEARERTOKEN']
|
| 11 |
headers = {"Authorization": bt }
|
| 12 |
|
| 13 |
+
def query(mood, select_model, filepath):
|
|
|
|
|
|
|
| 14 |
|
| 15 |
+
print (select_model);
|
| 16 |
+
print (filepath);
|
| 17 |
+
|
| 18 |
+
|
| 19 |
+
if (select_model=="Sentiment"):
|
| 20 |
+
response = requests.post(API_URL1, headers=headers, json=mood)
|
| 21 |
+
elif (select_model=="WhatIsThat"):
|
| 22 |
+
data = open(filepath, 'rb' ).read()
|
| 23 |
+
response = requests.post(API_URL2, headers=headers, data=data)
|
| 24 |
+
else:
|
| 25 |
+
data = open(filepath, 'rb' ).read()
|
| 26 |
+
response = requests.post(API_URL3, headers=headers, data=data)
|
| 27 |
+
return str(response.json())
|
| 28 |
+
|
| 29 |
+
def greet(mood,select_model,image):
|
| 30 |
+
output = query({"inputs":mood}, select_model, image)
|
| 31 |
print (str(output))
|
| 32 |
return str(output)
|
| 33 |
|
| 34 |
iface = gr.Interface(
|
| 35 |
+
fn=greet, inputs=["text", gr.Radio(choices=["Sentiment", "WhatIsThat", "HandWriting"],value="Sentiment"),gr.Image(type="filepath")], outputs="text")
|
| 36 |
iface.launch()
|