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 #7

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
5 changes: 5 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"cSpell.words": [
"jsonify"
]
}
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
2 changes: 1 addition & 1 deletion frontend/pages/MLProjects/_components/graph.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import axios from "axios";

const Graph = () => {
const [imageUrl, setImageUrl] = useState('');
const local_server_endpoint = "" // TODO
const local_server_endpoint = "http://localhost:8080" // TODO
useEffect(() => {
const fetchImage = async () => {
try {
Expand Down
2 changes: 1 addition & 1 deletion frontend/pages/MLProjects/_components/models.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import axios from "axios";
const Models = ({ props }) => {
// const [modelData, setModelData] = useState<ModelData | null>(null);
const [modelData, setModelData] = useState(null);
const local_server_endpoint = "" // TODO
const local_server_endpoint = "http://localhost:8080" // TODO

useEffect(() => {
const fetchModelData = async () => {
Expand Down
40 changes: 40 additions & 0 deletions frontend/pages/_components/indexMSG.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
// '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;
5 changes: 5 additions & 0 deletions frontend/pages/about.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export default function About() {
return(
<div> this is the About Page</div>
)
}
10 changes: 10 additions & 0 deletions frontend/pages/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import IndexMSG from "./_components/indexMSG";

export default function Home() {
return (
<div>
<h1>HOME</h1>
<IndexMSG />
</div>
)
}
6 changes: 6 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

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