KeerthiSattaluri commited on
Commit
d71ec70
·
1 Parent(s): 1e5c999
Files changed (2) hide show
  1. app.py +21 -8
  2. requirements.txt +4 -0
app.py CHANGED
@@ -1,22 +1,35 @@
1
-
2
  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()
 
 
1
  import gradio as gr
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()
requirements.txt ADDED
@@ -0,0 +1,4 @@
 
 
 
 
 
1
+
2
+ gradio==3.48.0
3
+ requests
4
+ fastai