peter2000 commited on
Commit
2c7a50d
1 Parent(s): 1c13ea2

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +18 -20
app.py CHANGED
@@ -5,28 +5,26 @@ pipe = pipeline("text-classification", model="jonas/sdg_classifier_osdg")
5
  pipe2 = pipeline("text-classification", model="peter2000/xlm-roberta-base-finetuned-osdg")
6
 
7
  sdg_dict = {
8
- 1:"SDG 1: End poverty in all its forms everywhere",
9
- 2:"SDG 2: End hunger, achieve food security and improved nutrition and promote sustainable agriculture",
10
- 3:"SDG3: Ensure healthy lives and promote well-being for all at all ages",
11
- 4:"SDG 4: Ensure inclusive and equitable quality education and promote lifelong learning opportunities for all",
12
- 5:"SDG 5: Achieve gender equality and empower all women and girls",
13
- 6:"SDG 6: Ensure availability and sustainable management of water and sanitation for all",
14
- 7:"SDG 7: Ensure access to affordable, reliable, sustainable and modern energy for all",
15
- 8:"SDG 8: Promote sustained, inclusive and sustainable economic growth, full and productive employment and decent work for all",
16
- 9:"SDG 9: Build resilient infrastructure, promote inclusive and sustainable industrialization and foster innovation",
17
- 10:"SDG 10: Reduce inequality within and among countries",
18
- 11:"SDG 11: Make cities and human settlements inclusive, safe, resilient and sustainable",
19
- 12:"SDG 12: Ensure sustainable consumption and production patterns",
20
- 13:"SDG 13: Take urgent action to combat climate change and its impacts*",
21
- 14:"SDG 14: Conserve and sustainably use the oceans, seas and marine resources for sustainable development",
22
- 15:"SDG 15: Protect, restore and promote sustainable use of terrestrial ecosystems, sustainably manage forests, combat desertification, and halt and reverse land degradation and halt biodiversity loss"
23
  }
24
 
25
  def predict(text):
26
  preds = pipe(text)[0]
27
- preds2 = pipe2(text)[0]
28
- return sdg_dict[preds["label"]], str(round(preds["score"], 5)*100) + " %",, preds2["label"], preds2["score"]
29
- ##return sdg_dict[int(preds["label"][0])], str(round(preds["score"], 5)*100) + " %", sdg_dict[int(preds2["label"][0])], str(round(preds2["score"], 5)*100) + " %"
30
 
31
  gradio_ui = gr.Interface(
32
  fn=predict,
@@ -42,8 +40,8 @@ gradio_ui = gr.Interface(
42
  gr.outputs.Textbox(label="Certainty")
43
  ],
44
  examples=[
45
- ["To secure sustainable development gains and build resilience in the region, there is an urgent need to undertake climate mitigation and adaptation action. Despite an estimated $391 billion in climate finance flows internationally in 2014, the gap between available climate finance and the financing required to limit global warming to two degrees Celsius and adapt to unavoidable impacts of climate change is growing. The present paper offers an overview of the climate finance landscape with a focus on the Asia-Pacific region, and of finance flows from international climate funds, multilateral development banks and subregional and national climate finance initiatives."],
46
- ["Making transportation inclusive means also ensuring the affordability of accessible transportation. Accessible ICTs, including mobile applications, government websites, public kiosks and automated teller machines, should be part of accessible urban development plans. Although compact cities can offer enormous potential for persons with disabilities, this potential will not materialize unless accessibility and nondiscrimination are prioritized."]
47
  ],
48
  )
49
 
 
5
  pipe2 = pipeline("text-classification", model="peter2000/xlm-roberta-base-finetuned-osdg")
6
 
7
  sdg_dict = {
8
+ '1':"SDG 1: End poverty in all its forms everywhere",
9
+ '2':"SDG 2: End hunger, achieve food security and improved nutrition and promote sustainable agriculture",
10
+ '3':"SDG3: Ensure healthy lives and promote well-being for all at all ages",
11
+ '4':"SDG 4: Ensure inclusive and equitable quality education and promote lifelong learning opportunities for all",
12
+ '5':"SDG 5: Achieve gender equality and empower all women and girls",
13
+ '6':"SDG 6: Ensure availability and sustainable management of water and sanitation for all",
14
+ '7':"SDG 7: Ensure access to affordable, reliable, sustainable and modern energy for all",
15
+ '8':"SDG 8: Promote sustained, inclusive and sustainable economic growth, full and productive employment and decent work for all",
16
+ '9':"SDG 9: Build resilient infrastructure, promote inclusive and sustainable industrialization and foster innovation",
17
+ '10':"SDG 10: Reduce inequality within and among countries",
18
+ '11':"SDG 11: Make cities and human settlements inclusive, safe, resilient and sustainable",
19
+ '12':"SDG 12: Ensure sustainable consumption and production patterns",
20
+ '13':"SDG 13: Take urgent action to combat climate change and its impacts*",
21
+ '14':"SDG 14: Conserve and sustainably use the oceans, seas and marine resources for sustainable development",
22
+ '15':"SDG 15: Protect, restore and promote sustainable use of terrestrial ecosystems, sustainably manage forests, combat desertification, and halt and reverse land degradation and halt biodiversity loss"
23
  }
24
 
25
  def predict(text):
26
  preds = pipe(text)[0]
27
+ return sdg_dict[preds["label"]], str(round(preds["score"], 5)*100) + " %"
 
 
28
 
29
  gradio_ui = gr.Interface(
30
  fn=predict,
 
40
  gr.outputs.Textbox(label="Certainty")
41
  ],
42
  examples=[
43
+ ["The Paris Agreement, adopted in 2015, aims to strengthen the global response to the threat of climate change by keeping a global temperature rise this century well below 2 degrees Celsius above pre-industrial levels. The agreement also aims to strengthen the ability of countries to deal with the impacts of climate change, through appropriate financial flows, a new technology framework and an enhanced capacity building framework."],
44
+ ["Gender equality is not only a fundamental human right, but a necessary foundation for a peaceful, prosperous and sustainable world. There has been progress over the last decades: More girls are going to school, fewer girls are forced into early marriage, more women are serving in parliament and positions of leadership, and laws are being reformed to advance gender equality."]
45
  ],
46
  )
47