Update app.py
Browse files
app.py
CHANGED
|
@@ -1,28 +1,19 @@
|
|
| 1 |
-
|
| 2 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3 |
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
# Get uploaded file
|
| 13 |
-
file = request.files["file"]
|
| 14 |
-
|
| 15 |
-
# Read CSV file using pandas
|
| 16 |
-
try:
|
| 17 |
-
df = pd.read_csv(file)
|
| 18 |
-
except Exception as e:
|
| 19 |
-
return jsonify({"message": "Invalid CSV file"}), 400
|
| 20 |
-
|
| 21 |
-
# Use Hugging Face transformer with df here
|
| 22 |
-
# (your specific code for processing with Hugging Face)
|
| 23 |
-
|
| 24 |
-
# Return response
|
| 25 |
-
return jsonify({"message": "File uploaded and processed", "data": df.to_json()})
|
| 26 |
|
| 27 |
if __name__ == "__main__":
|
| 28 |
-
|
|
|
|
| 1 |
+
def process_csv(file):
|
| 2 |
+
if file is None:
|
| 3 |
+
return "No file uploaded"
|
| 4 |
+
|
| 5 |
+
# Read the CSV file into a DataFrame
|
| 6 |
+
df = pd.read_csv(StringIO(file.decode("utf-8")))
|
| 7 |
+
return df
|
| 8 |
|
| 9 |
+
# Create the Gradio interface
|
| 10 |
+
iface = gr.Interface(
|
| 11 |
+
fn=process_csv,
|
| 12 |
+
inputs=gr.File(type="csv", label="Upload CSV File"),
|
| 13 |
+
outputs="dataframe",
|
| 14 |
+
title="CSV File Upload",
|
| 15 |
+
description="Upload a CSV file and convert it to a pandas DataFrame."
|
| 16 |
+
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 17 |
|
| 18 |
if __name__ == "__main__":
|
| 19 |
+
iface.launch()
|