Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

frontend and backend setup #2

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,9 @@ __pycache__/
*.py[cod]

server/venv
server/myenv
server/myenv
server/venv




2 changes: 1 addition & 1 deletion frontend/pages/MLProjects/_components/analysis.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ dotenv.config();

const Analysis = () => {
const [imageUrl, setImageUrl] = useState('');
const local_server_endpoint = "" // TODO
const local_server_endpoint = "http://localhost:8080/" // TODO
useEffect(() => {
const fetchImage = async () => {
try {
Expand Down
43 changes: 43 additions & 0 deletions frontend/pages/_components/indexMSG.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import { useEffect, useState } from "react";
import axios from "axios";

// 'message': "Hello world!",
// 'people': ["Aa", "Bb", "Cc"]


const IndexMSG = () => {
const [msg, setMsg] = useState(null);

console.log("HERE");
useEffect(() => {
const fetchMsg = async () => {
try {
const res = await axios.get("http://localhost:8080");
console.log("RES", res);
setMsg(res.data);
} catch (error) {
console.log(error);
}
}
fetchMsg();
}, []);

return (
<div>
<h1>DUMMY MESSAGE</h1>
{/* {msg ? <h1>{msg}</h1> : <h1>LOADING...</h1>} */}
{msg ? (
<div>
<h1>{msg.message}</h1>
{msg.people.map((person, index) => (
<h1 key={index}>{person}</h1>
))}
</div>
) : (
<h1>LOADING...</h1>
)}
</div>
)
}

export default IndexMSG;
9 changes: 9 additions & 0 deletions frontend/pages/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import IndexMSG from "./_components/indexMSG"
export default function Home(){
return (
<div>
<h1> HALLO </h1>
<IndexMSG></IndexMSG>
</div>
)
}
Binary file added server/first_graph.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
68 changes: 68 additions & 0 deletions server/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,71 @@
from eda import analysis
from flask_restful import Api, Resource

app = Flask(__name__)

CORS(app)
api = Api(app)

all_models = ['logistic_regression', 'k_nearest_neighbors', 'support_vector_machine', 'decision_tree', 'random_forest', 'gradient_boosting', 'naive_bayes', 'neural_network', 'ada_boost', 'xg_boost']
@app.after_request
def after_request(response):
response.headers.add('Access-Control-Allow-Origin', '*')
response.headers.add('Access-Control-Allow-Headers', 'Content-Type,Authorization')
response.headers.add('Access-Control-Allow-Methods', 'GET,PUT,POST,DELETE,OPTIONS')
return response

@app.route("/", methods=['GET'])
def return_home():
return jsonify({
'message': "Hello world!",
'people': ["Aa", "Bb", "Cc"]
})

@app.route('/first_image', methods = ['GET'])
def get_image():
result = run_algorithm(all_models)
return send_file('first_graph.png', mimetype='image/png')

@app.route('/analysis', methods = ['GET'])
def analyse():
# analysis()
return send_file('analysis.png', mimetype='image/png')

@app.route('/models', methods = ['GET', 'POST'])
def get_models():
if request.method == 'GET':
result = run_algorithm(all_models)
return jsonify({
'models': result
})

if request.method == 'POST':
try:
data = request.json
models_to_run = data.get('models')
result = run_algorithm(models_to_run)
return jsonify({
'models': result
}), 200
except Exception as e:
return jsonify({
'error': 'Invalid request',
'details': str(e)
}), 400


# @app.route('/download_first_graph')
# def download_first_graph():
# run_algorithm() # Generate the graphs
# return send_file('first_graph.png', as_attachment=True)

# @app.route('/download_second_graph')
# def download_second_graph():
# run_algorithm() # Generate the graphs
# return send_file('second_graph.png', as_attachment=True)

if __name__ == "__main__":
app.run(debug=True, port=8080)

# def create_app():
# return app