Spaces:
Sleeping
Sleeping
oooo
Browse files- app.py +35 -0
- requirements.txt +4 -0
app.py
ADDED
@@ -0,0 +1,35 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
'''
|
2 |
+
Author: i316984 daisy.mao@sap.com
|
3 |
+
Date: 2024-02-16 12:02:26
|
4 |
+
LastEditors: i316984 daisy.mao@sap.com
|
5 |
+
LastEditTime: 2024-02-16 12:30:20
|
6 |
+
FilePath: /undefined/Users/i316984_1/hackaithon101/app.py
|
7 |
+
Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
|
8 |
+
'''
|
9 |
+
|
10 |
+
import gradio as gr
|
11 |
+
import requests
|
12 |
+
import os
|
13 |
+
import json
|
14 |
+
|
15 |
+
API_URL = "https://api-inference.huggingface.co/models/cardiffnlp/twitter-roberta-base-sentiment"
|
16 |
+
|
17 |
+
bt = os.environ['HACKAITHONBEARERTOKEN']
|
18 |
+
headers = {"Authorization": bt }
|
19 |
+
key_mapping = {'LABEL_0':'negative','LABEL_1':'neutral','LABEL_2':'positive'}
|
20 |
+
|
21 |
+
def query(data):
|
22 |
+
response = requests.post(API_URL, headers=headers, json=data)
|
23 |
+
list_json = response.json()
|
24 |
+
return "V2"+json.dumps([{k: key_mapping.get(v, v) for k, v in dict_t.items()}
|
25 |
+
for dict_t in list_json[0]], indent=4)
|
26 |
+
|
27 |
+
|
28 |
+
def greet(howareyoufeeling):
|
29 |
+
output = query({"inputs":howareyoufeeling})
|
30 |
+
print (str(output))
|
31 |
+
return str(output)
|
32 |
+
|
33 |
+
iface = gr.Interface(
|
34 |
+
fn=greet, inputs=["text"], outputs="text", allow_flagging="never")
|
35 |
+
iface.launch()
|
requirements.txt
ADDED
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
1 |
+
|
2 |
+
gradio==3.48.0
|
3 |
+
requests
|
4 |
+
fastai
|