Created
April 27, 2018 12:26
-
-
Save phsheth/770f6345d3c5b9f4f7ceced0dd1eb104 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from flask import Flask, make_response, request | |
import io | |
import csv | |
import numpy as np | |
import pandas as pd | |
app = Flask(__name__) | |
def transform(text_file_contents): | |
return text_file_contents.replace("=", ",") | |
@app.route('/') | |
def form(): | |
return """ | |
<html> | |
<body> | |
<h1>Transform a file demo</h1> | |
<form action="/transform" method="post" enctype="multipart/form-data"> | |
<input type="file" name="data_file" /> | |
<input type="submit" /> | |
</form> | |
</body> | |
</html> | |
""" | |
@app.route('/transform', methods=["POST"]) | |
def transform_view(): | |
f = request.files['data_file'] | |
if not f: | |
return "No file" | |
datafile = pd.read_csv(f) | |
print(datafile) | |
return datafile.values() | |
if __name__ == "__main__": | |
app.run(host='0.0.0.0', port=5001, debug=True) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment