Youssouf Traore
commited on
Commit
·
e8d0f18
1
Parent(s):
da37e36
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,35 +1,38 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
from covid import Covid
|
| 3 |
import pandas as pd
|
|
|
|
| 4 |
|
| 5 |
# Fonction pour obtenir les données COVID-19 d'un pays
|
| 6 |
def get_covid_data(country):
|
|
|
|
|
|
|
| 7 |
covid = Covid()
|
| 8 |
-
data = covid.get_status_by_country_name(
|
| 9 |
return data
|
| 10 |
|
| 11 |
-
# Fonction pour afficher les données sous forme de
|
| 12 |
def display_table(data):
|
| 13 |
df = pd.DataFrame.from_dict(data, orient='index')
|
| 14 |
df = df.rename(columns={
|
| 15 |
-
'confirmed': '
|
| 16 |
-
'active': '
|
| 17 |
-
'deaths': '
|
| 18 |
-
'recovered': '
|
| 19 |
})
|
| 20 |
-
|
| 21 |
-
return
|
| 22 |
|
| 23 |
-
# Interface Gradio
|
| 24 |
iface = gr.Interface(fn=get_covid_data,
|
| 25 |
inputs="text",
|
| 26 |
-
outputs=
|
| 27 |
title="COVID-19 Data by Country",
|
| 28 |
-
description="
|
|
|
|
| 29 |
|
| 30 |
# Ajouter la fonction display_table à l'interface Gradio
|
| 31 |
-
iface.
|
| 32 |
-
iface.output(0).update(display_table)
|
| 33 |
|
| 34 |
# Lancement de l'interface
|
| 35 |
iface.launch()
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
from covid import Covid
|
| 3 |
import pandas as pd
|
| 4 |
+
import translate
|
| 5 |
|
| 6 |
# Fonction pour obtenir les données COVID-19 d'un pays
|
| 7 |
def get_covid_data(country):
|
| 8 |
+
translator = translate.Translator(to_lang="fr")
|
| 9 |
+
country_fr = translator.translate(country).lower()
|
| 10 |
covid = Covid()
|
| 11 |
+
data = covid.get_status_by_country_name(country_fr)
|
| 12 |
return data
|
| 13 |
|
| 14 |
+
# Fonction pour afficher les données sous forme de dictionnaire
|
| 15 |
def display_table(data):
|
| 16 |
df = pd.DataFrame.from_dict(data, orient='index')
|
| 17 |
df = df.rename(columns={
|
| 18 |
+
'confirmed': 'Cas Confirmés',
|
| 19 |
+
'active': 'Cas Actifs',
|
| 20 |
+
'deaths': 'Décès',
|
| 21 |
+
'recovered': 'Guérisons'
|
| 22 |
})
|
| 23 |
+
table_dict = df.to_dict(orient='index')
|
| 24 |
+
return table_dict
|
| 25 |
|
| 26 |
+
# Interface Gradio
|
| 27 |
iface = gr.Interface(fn=get_covid_data,
|
| 28 |
inputs="text",
|
| 29 |
+
outputs="json",
|
| 30 |
title="COVID-19 Data by Country",
|
| 31 |
+
description="Entrez le nom d'un pays pour obtenir les données COVID-19.",
|
| 32 |
+
example="France")
|
| 33 |
|
| 34 |
# Ajouter la fonction display_table à l'interface Gradio
|
| 35 |
+
iface.out = display_table
|
|
|
|
| 36 |
|
| 37 |
# Lancement de l'interface
|
| 38 |
iface.launch()
|