Update app.py
Browse files
app.py
CHANGED
|
@@ -1,27 +1,28 @@
|
|
| 1 |
-
import
|
| 2 |
import pandas as pd
|
| 3 |
-
from io import StringIO
|
| 4 |
|
|
|
|
| 5 |
|
| 6 |
-
|
| 7 |
-
|
|
|
|
|
|
|
|
|
|
| 8 |
|
| 9 |
-
#
|
| 10 |
-
|
| 11 |
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
# To read file as pandas dataframe:
|
| 18 |
-
# (Adjust the parameters like `sep`, `header` if necessary)
|
| 19 |
-
df = pd.read_csv(uploaded_file)
|
| 20 |
-
|
| 21 |
-
# Display the dataframe
|
| 22 |
-
st.write(df)
|
| 23 |
|
|
|
|
|
|
|
| 24 |
|
|
|
|
|
|
|
| 25 |
|
| 26 |
if __name__ == "__main__":
|
| 27 |
-
|
|
|
|
| 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)
|