Update app.py
Browse files
app.py
CHANGED
|
@@ -1,37 +1,27 @@
|
|
| 1 |
import streamlit as st
|
| 2 |
-
import
|
|
|
|
| 3 |
from PIL import Image
|
| 4 |
-
import
|
|
|
|
| 5 |
|
| 6 |
-
st.set_page_config(page_title="
|
| 7 |
-
st.title("🎨
|
| 8 |
|
| 9 |
-
|
|
|
|
|
|
|
| 10 |
|
| 11 |
-
|
| 12 |
|
|
|
|
| 13 |
if uploaded_file:
|
| 14 |
-
|
| 15 |
-
|
| 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("
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 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)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|