File size: 1,768 Bytes
5ce2ec4
 
 
 
 
 
 
 
9d09431
ad5bd30
9d09431
 
 
 
00f28bf
5ce2ec4
9d09431
5ce2ec4
9d09431
5ce2ec4
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import streamlit as st
import requests

st.title('๐Ÿ‡ช๐Ÿ‡บ ๐Ÿท๏ธ Eurovoc Tagger')
st.write("This page in a demonstration interface of the Eurovoc Tagger API. It allows you to test how tag a text with Eurovoc concepts.")
q = st.text_area('Enter a text:', 'The Union condemns the continuing grave human rights violations by the Myanmar armed forces, including torture, sexual and gender-based violence, the persecution of civil society actors, human rights defenders and journalists, and attacks on the civilian population, including ethnic and religious minorities.',
                 height=200, max_chars=5000)

API_URL_EN = "https://lcs3f8pwcn03ri5q.eu-west-1.aws.endpoints.huggingface.cloud"
API_URL_EU = "https://wu0h9yuxkbna7e7c.eu-west-1.aws.endpoints.huggingface.cloud"
apis = {"Multilingual ๐Ÿ‡ช๐Ÿ‡บ": API_URL_EU,
        "English ๐Ÿ‡ฌ๐Ÿ‡ง (Deprecated) ": API_URL_EU
        }

k = st.slider('How many tags', 1, 20, 4)
t = st.slider("Threshold", 0.0, 1.0, 0.1)
lang = st.selectbox("Language", apis.keys())

hf_token = st.secrets["HF_TOKEN"]
headers = {
    "Authorization": f"Bearer {hf_token}",
    "Content-Type": "application/json"
}


def query(payload):
    response = requests.post(apis[lang], headers=headers, json=payload)
    assert response.status_code == 200, response.text
    return response.json()


payload = {
    "inputs": q,
    "topk": k,
    "threshold": t
    }

st.markdown("---")

with st.spinner("Request in progress, please wait..."):
    try:
        print(payload)
        r = query(payload)
    except Exception as e:
        st.error(e)
        st.write("The server is probably waking up, so please wait a minute and reload the page.")
        st.stop()
st.subheader("Results")
st.dataframe(r['results'], width=1000, height=600)