scampion commited on
Commit
5ce2ec4
1 Parent(s): 7e0db47

first import

Browse files
Files changed (1) hide show
  1. app.py +48 -0
app.py ADDED
@@ -0,0 +1,48 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import requests
3
+
4
+ st.title('🇪🇺 🏷️ Eurovoc Tagger')
5
+ 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.")
6
+ 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.',
7
+ height=200, max_chars=5000)
8
+
9
+ k = st.slider('How many tags', 1, 20, 5)
10
+ t = st.slider("Threshold", 0.0, 1.0, 0.1)
11
+ lang = st.selectbox("Language", ["en", "fr"])
12
+
13
+
14
+ API_URL_EN = "https://xizrpi3gdk25o8lm.eu-west-1.aws.endpoints.huggingface.cloud"
15
+ API_URL_FR = "https://hshbzvevs03wq4io.eu-west-1.aws.endpoints.huggingface.cloud"
16
+ apis = {"en": API_URL_EN, "fr": API_URL_FR}
17
+
18
+ hf_token = st.secrets["HF_TOKEN"]
19
+ headers = {
20
+ "Authorization": f"Bearer {hf_token}",
21
+ "Content-Type": "application/json"
22
+ }
23
+
24
+
25
+ def query(payload):
26
+ response = requests.post(apis[lang], headers=headers, json=payload)
27
+ assert response.status_code == 200, response.text
28
+ return response.json()
29
+
30
+
31
+ payload = {
32
+ "inputs": q,
33
+ "topk": k,
34
+ "threshold": t
35
+ }
36
+
37
+ st.markdown("---")
38
+
39
+ with st.spinner("Request in progress, please wait..."):
40
+ try:
41
+ print(payload)
42
+ r = query(payload)
43
+ except Exception as e:
44
+ st.error(e)
45
+ st.write("The server is probably waking up, so please wait a minute and reload the page.")
46
+ st.stop()
47
+ st.subheader("Results")
48
+ st.dataframe(r['results'], width=1000, height=600)