Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
from setfit import SetFitModel
|
| 3 |
+
|
| 4 |
+
# Download from Hub and run inference
|
| 5 |
+
model = SetFitModel.from_pretrained("peter2000/vulnerable-groups-setfit")
|
| 6 |
+
|
| 7 |
+
|
| 8 |
+
group_dict = {
|
| 9 |
+
1: 'Women and girls',
|
| 10 |
+
2: 'Children and youth',
|
| 11 |
+
3: 'Landlocked countries',
|
| 12 |
+
4: 'Outdoor workers',
|
| 13 |
+
5: 'Riverine and flood-prone areas',
|
| 14 |
+
6: 'Small-scale farmers',
|
| 15 |
+
7: 'Men and boys',
|
| 16 |
+
8: 'Small island developing states (SIDS)',
|
| 17 |
+
9: 'Fisherfolk and fishing communities',
|
| 18 |
+
10: 'Children with disabilities',
|
| 19 |
+
11: 'Low-income households',
|
| 20 |
+
12: 'Rural communities',
|
| 21 |
+
13: 'Pregnant women and new mothers',
|
| 22 |
+
14: 'Young adults',
|
| 23 |
+
15: 'Urban slums',
|
| 24 |
+
16: 'Gender non-conforming individuals',
|
| 25 |
+
17: 'Remote communities',
|
| 26 |
+
18: 'Older adults and the elderly',
|
| 27 |
+
19: 'Elderly population',
|
| 28 |
+
20: 'Mountain communities',
|
| 29 |
+
21: 'People with disabilities',
|
| 30 |
+
22: 'Indigenous peoples',
|
| 31 |
+
23: 'Informal settlements and slums',
|
| 32 |
+
24: 'Coastal communities',
|
| 33 |
+
25: 'Informal sector workers',
|
| 34 |
+
26: 'Drought-prone regions',
|
| 35 |
+
27: 'People with pre-existing health conditions',
|
| 36 |
+
28: 'Small-scale farmers and subsistence agriculture',
|
| 37 |
+
29: 'Migrants and displaced populations'}
|
| 38 |
+
|
| 39 |
+
def predict(text):
|
| 40 |
+
preds = model(text)[0].item()
|
| 41 |
+
return preds
|
| 42 |
+
return group_dict[preds]
|
| 43 |
+
|
| 44 |
+
gradio_ui = gr.Interface(
|
| 45 |
+
fn=predict,
|
| 46 |
+
title="Predict reference to vulnerable groups",
|
| 47 |
+
description="This Space showcases.",
|
| 48 |
+
inputs=[
|
| 49 |
+
gr.inputs.Textbox(lines=5, label="Paste some text here"),
|
| 50 |
+
],
|
| 51 |
+
outputs=[
|
| 52 |
+
gr.outputs.Textbox(label="Vulnerable group"),
|
| 53 |
+
|
| 54 |
+
],
|
| 55 |
+
examples=[
|
| 56 |
+
["To promote gender equality and empower men and boys as agents of change in climate adaptation efforts, we aim to engage 300,000 men and boys in gender-responsive climate change adaptation initiatives by 2030, focusing on capacity building, leadership development, and community engagement."],
|
| 57 |
+
["To preserve the traditional knowledge and resources of indigenous peoples in the face of climate change, we commit to protecting and restoring 2 million hectares of indigenous peoples' traditional lands by 2030, focusing on sustainable land management practices, ecosystem restoration, and the conservation of biodiversity"]
|
| 58 |
+
],
|
| 59 |
+
)
|
| 60 |
+
|
| 61 |
+
gradio_ui.launch(debug=True)
|