yanivbl commited on
Commit
10f3bfe
·
1 Parent(s): 3240aa0

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +16 -25
app.py CHANGED
@@ -1,28 +1,19 @@
1
- from flask import Flask, request, jsonify
2
- import pandas as pd
 
 
 
 
 
3
 
4
- app = Flask(__name__)
5
-
6
- @app.route("/upload", methods=["POST"])
7
- def upload_csv():
8
- # Check if file is uploaded
9
- if "file" not in request.files:
10
- return jsonify({"message": "No file uploaded"}), 400
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
- app.run(debug=True)
 
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()