yanivbl commited on
Commit
a3bbc72
·
1 Parent(s): 1c00409

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +19 -18
app.py CHANGED
@@ -1,27 +1,28 @@
1
- import streamlit as st
2
  import pandas as pd
3
- from io import StringIO
4
 
 
5
 
6
- def main():
7
- st.title("CSV File Upload App")
 
 
 
8
 
9
- # File uploader widget
10
- uploaded_file = st.file_uploader("Choose a CSV file", type="csv")
11
 
12
- if uploaded_file is not None:
13
- # To read file as string:
14
- stringio = StringIO(uploaded_file.getvalue().decode("utf-8"))
15
- string_data = stringio.read()
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
- main()
 
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)