ByteMan commited on
Commit
dc5a7a5
1 Parent(s): 77cdebd

Add application fil3e

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