Skip to content

Commit

Permalink
Merge pull request #35 from grant-baer/refactor-generate-image
Browse files Browse the repository at this point in the history
Refactor image generation into backend call
  • Loading branch information
caseyavila authored Nov 15, 2023
2 parents ade2ebc + 0e0dd74 commit ddaaad9
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 64 deletions.
14 changes: 11 additions & 3 deletions Backend/backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,17 @@
"http://127.0.0.1:5001" # This is where db_access.py is running.
)

@app.route("/generate_image", methods=["POST"])
def generate_image():
data = request.get_json()
url = "https://imagegolf.io/api/generate"
url_data = {
"inputValue": data["prompt"]
}

r = requests.post(url, json=url_data)

return r.json()

@app.route("/store_image", methods=["POST"])
def store_image():
Expand Down Expand Up @@ -94,7 +104,7 @@ def login():


@app.route("/create_user", methods=["POST"])
def register():
def create_user():
print("received register request")
print(request, request.data)
return jsonify({"message": "No endpoint called create_user, perhaps you meant: /register"})
Expand Down Expand Up @@ -147,8 +157,6 @@ def register():
return jsonify({"message": "Failed to create user!!"})




if __name__ == "__main__":
try:
app.run(port=5000, debug=True)
Expand Down
22 changes: 0 additions & 22 deletions Backend/generate_url.py

This file was deleted.

24 changes: 0 additions & 24 deletions Frontend/src/pages/api/generateURL.js

This file was deleted.

24 changes: 9 additions & 15 deletions Frontend/src/pages/create.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import React, { useState } from "react";
import axios from "axios";
import Image from "next/image";

export default function Home() {
Expand All @@ -10,23 +11,16 @@ export default function Home() {
e.preventDefault();

try {
const response = await fetch("/api/generateURL", {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({
inputValue: text,
}),
});
const response = await axios.post(
"http://localhost:5000/generate_image",
{"prompt": text}
);

const data = await response.json();

if (data.url) {
setUrl(data.url);
if (response.data.output) {
setUrl(response.data.output);
setImageAccepted(null); // Reset the decision state when a new image is fetched
} else {
console.error("Failed to get URL.");
} else if (response.data.error) {
console.error(response.data.error);
}
} catch (error) {
console.error("Error:", error);
Expand Down

0 comments on commit ddaaad9

Please sign in to comment.