File size: 1,201 Bytes
ab6b1dd 64a432f ab6b1dd 64a432f 06d7fc4 c88d6f0 06d7fc4 64a432f 06d7fc4 ab6b1dd |
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 |
import gradio as gr
from covid import Covid
import pandas as pd
# Fonction pour obtenir les données COVID-19 d'un pays
def get_covid_data(country):
covid = Covid()
data = covid.get_status_by_country_name(country)
return data
# Fonction pour afficher les données sous forme de tableau
def display_table(data):
df = pd.DataFrame.from_dict(data, orient='index')
df = df.rename(columns={
'confirmed': 'Confirmed Cases',
'active': 'Active Cases',
'deaths': 'Deaths',
'recovered': 'Recovered Cases'
})
table_html = df.to_html()
return table_html
# Interface Gradio avec une liste déroulante
iface = gr.Interface(fn=get_covid_data,
inputs="text",
outputs=gr.outputs.Table(header=["Confirmed Cases", "Active Cases", "Deaths", "Recovered Cases"]),
title="COVID-19 Data by Country",
description="Enter the name of a country to get COVID-19 data.",
example="France")
# Ajouter la fonction display_table à l'interface Gradio
iface.outs[0].type = "python"
iface.outs[0].update(display_table)
# Lancement de l'interface
iface.launch()
|