Jacek Konopelski commited on
Commit
f85e68f
1 Parent(s): 76d565a
Files changed (1) hide show
  1. app.py +22 -8
app.py CHANGED
@@ -3,20 +3,34 @@ import gradio as gr
3
  import requests
4
  import os
5
 
6
- API_URL = "https://api-inference.huggingface.co/models/cardiffnlp/twitter-roberta-base-sentiment"
 
 
7
 
8
- bt = os.environ['HACKAITHONBEARERTOKEN']
9
  headers = {"Authorization": bt }
10
 
11
- def query(data):
12
- response = requests.post(API_URL, headers=headers, json=data)
13
- return "V2"+str(response.json())
14
 
15
- def greet(howareyoufeeling):
16
- output = query({"inputs":howareyoufeeling})
 
 
 
 
 
 
 
 
 
 
 
 
 
 
17
  print (str(output))
18
  return str(output)
19
 
20
  iface = gr.Interface(
21
- fn=greet, inputs=["text"], outputs="text", allow_flagging="never")
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['RobertaSecret']
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()