senthil3226w commited on
Commit
7ab5dbd
·
verified ·
1 Parent(s): dedcf57

Update main.py

Browse files
Files changed (1) hide show
  1. main.py +36 -5
main.py CHANGED
@@ -1,7 +1,38 @@
1
- from fastapi import FastAPI
 
 
 
 
2
 
3
- app = FastAPI()
4
 
5
- @app.get("/")
6
- def read_root():
7
- return {"Hello": "World!"}
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from flask import Flask, render_template, request, redirect, url_for
2
+ from utility import load_image,interpolate_batch,interpolate_single
3
+ from io import BytesIO
4
+ from PIL import Image
5
+ import base64
6
 
7
+ app = Flask(__name__)
8
 
9
+
10
+
11
+ def convert_frames_to_base64(frames):
12
+ """Converts numpy image arrays to base64 strings for displaying in HTML."""
13
+ base64_frames = []
14
+ for frame in frames:
15
+ img = Image.fromarray((frame * 255).astype(np.uint8))
16
+ buffered = BytesIO()
17
+ img.save(buffered, format="PNG")
18
+ base64_str = base64.b64encode(buffered.getvalue()).decode("utf-8")
19
+ base64_frames.append(base64_str)
20
+ return base64_frames
21
+
22
+ @app.route("/", methods=["GET", "POST"])
23
+ def index():
24
+ if request.method == "POST":
25
+ img1_url = request.form.get("img1_url")
26
+ img2_url = request.form.get("img2_url")
27
+
28
+ if not img1_url or not img2_url:
29
+ return redirect(url_for("index"))
30
+
31
+ frames = interpolate_single(img1_url, img2_url)
32
+ if frames is not None:
33
+ base64_frames = convert_frames_to_base64(frames)
34
+ return render_template("result.html", frames=base64_frames)
35
+ else:
36
+ return "Error processing images.", 500
37
+
38
+ return render_template("index.html")