Fanu2 commited on
Commit
58a3156
·
verified ·
1 Parent(s): 0a88f6b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +19 -29
app.py CHANGED
@@ -1,37 +1,27 @@
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.")
 
1
  import streamlit as st
2
+ import cv2
3
+ import numpy as np
4
  from PIL import Image
5
+ import paddle
6
+ from ppgan.apps import AnimeGANPredictor
7
 
8
+ st.set_page_config(page_title="AnimeGAN", layout="centered")
9
+ st.title("🎨 Convert Your Photo to Anime Style")
10
 
11
+ @st.cache_resource
12
+ def load_model():
13
+ return AnimeGANPredictor()
14
 
15
+ predictor = load_model()
16
 
17
+ uploaded_file = st.file_uploader("Upload a photo", type=["jpg", "jpeg", "png"])
18
  if uploaded_file:
19
+ image = Image.open(uploaded_file).convert("RGB")
20
+ st.image(image, caption="Original Image", use_column_width=True)
 
 
21
 
22
+ if st.button("Generate Anime"):
23
+ img_np = np.array(image)
24
+ img_bgr = cv2.cvtColor(img_np, cv2.COLOR_RGB2BGR)
25
+ result = predictor.run(img_bgr)
26
+ result_rgb = cv2.cvtColor(result, cv2.COLOR_BGR2RGB)
27
+ st.image(result_rgb, caption="Anime Style", use_column_width=True)