| import gradio as gr | |
| import pandas as pd | |
| from io import StringIO | |
| # Global variable to hold the DataFrame | |
| global_df = None | |
| def process_csv(file): | |
| global global_df | |
| if file is None: | |
| return None | |
| # Read the CSV file into a DataFrame and store it in the global variable | |
| global_df = pd.read_csv(StringIO(file.decode("utf-8"))) | |
| return None # Return None as we don't want to show any output | |
| # Create the Gradio interface | |
| iface = gr.Interface( | |
| fn=process_csv, | |
| inputs=gr.File(type="binary", label="Upload CSV File"), | |
| outputs=gr.components.Label(), # Use Label as a placeholder output | |
| title="CSV File Upload", | |
| description="Upload a CSV file to load it into a pandas DataFrame." | |
| ) | |
| if __name__ == "__main__": | |
| iface.launch() | |