Fanu2 commited on
Commit
93bcd22
·
verified ·
1 Parent(s): 1f64d61

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +37 -0
app.py ADDED
@@ -0,0 +1,37 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import os
3
+ from PIL import Image
4
+ import subprocess
5
+
6
+ st.set_page_config(page_title="PaddleGAN Editor", layout="wide")
7
+ st.title("🎨 PaddleGAN Image Editor")
8
+
9
+ task = st.selectbox("Choose a task", ["Photo2Cartoon", "GPEN Face Enhancement"])
10
+
11
+ uploaded_file = st.file_uploader("Upload an image", type=["jpg", "png"])
12
+
13
+ if uploaded_file:
14
+ input_path = f"input.jpg"
15
+ with open(input_path, "wb") as f:
16
+ f.write(uploaded_file.read())
17
+ st.image(Image.open(input_path), caption="Uploaded Image", use_column_width=True)
18
+
19
+ if st.button("Run PaddleGAN"):
20
+ if task == "Photo2Cartoon":
21
+ cmd = f"python tools/infer.py --config configs/photo2cartoon.yaml --input_dir {input_path} --output_dir output"
22
+ elif task == "GPEN Face Enhancement":
23
+ cmd = f"python tools/infer.py --config configs/gpen.yaml --input_dir {input_path} --output_dir output"
24
+ else:
25
+ st.error("Unsupported task.")
26
+ st.stop()
27
+
28
+ with st.spinner("Running PaddleGAN..."):
29
+ subprocess.run(cmd, shell=True)
30
+
31
+ result_path = "output/result.jpg"
32
+ if os.path.exists(result_path):
33
+ st.image(Image.open(result_path), caption="Result", use_column_width=True)
34
+ with open(result_path, "rb") as f:
35
+ st.download_button("📥 Download Result", f.read(), "edited.jpg", "image/jpeg")
36
+ else:
37
+ st.error("No result found.")