Spaces:
Runtime error
Runtime error
Create app2.py
Browse files
app2.py
ADDED
@@ -0,0 +1,24 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
import pandas as pd
|
3 |
+
|
4 |
+
# Function to load and preview CSV
|
5 |
+
def preview_csv(file):
|
6 |
+
if file is None:
|
7 |
+
return "No file uploaded."
|
8 |
+
try:
|
9 |
+
df = pd.read_csv(file.name)
|
10 |
+
return df.head() # Show the first 5 rows
|
11 |
+
except Exception as e:
|
12 |
+
return f"Error reading CSV: {e}"
|
13 |
+
|
14 |
+
# Gradio interface
|
15 |
+
iface = gr.Interface(
|
16 |
+
fn=preview_csv,
|
17 |
+
inputs=gr.File(label="Upload CSV File", file_types=[".csv"]),
|
18 |
+
outputs=gr.Dataframe(label="CSV Preview"),
|
19 |
+
title="CSV Preview App",
|
20 |
+
description="Upload a CSV file to see the first 5 rows."
|
21 |
+
)
|
22 |
+
|
23 |
+
if __name__ == "__main__":
|
24 |
+
iface.launch()
|