0

I would like to upload a CSV file and update a table with the content and finally create a plot with the content, but I am stuck connecting all the components. I also could not find any good documentation of this.

import gradio as gr

default_csv = "Phase,Activity,Start date,End date\n\"Mapping the Field\",\"Literature review\",2024-01-01,2024-01-31"

def process_csv_text(text):
    print('process_csv_text')
    print(text)
    df = pd.read_csv(StringIO(text), parse_dates=["Start date", "End date"])
    return df

with gr.Blocks() as demo:
    upload_button = gr.UploadButton(label="Upload Timetable", file_types = ['.csv'], live=True, file_count = "single")    
    table = gr.Dataframe(headers=["Phase", "Activity", "Start date", "End date"], col_count=4, default=process_csv_text(default_csv))
    image = gr.Plot()
    upload_button.click(fn=process_csv_text, inputs=upload_button, outputs=table, api_name="upload_csv")

demo.launch()
Soerendip
  • 7,684
  • 15
  • 61
  • 128

0 Answers0