Hammad712 commited on
Commit
ba17129
1 Parent(s): 210e7b2

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +18 -3
app.py CHANGED
@@ -5,6 +5,7 @@ import numpy as np
5
  from huggingface_hub import HfApi, hf_hub_download
6
  from PIL import Image
7
  from io import BytesIO
 
8
 
9
  # Hugging Face credentials
10
  api = HfApi()
@@ -39,6 +40,11 @@ def infer_image(model, image):
39
  generated_img = (generated_img * 127.5 + 127.5).numpy().astype(np.uint8) # De-normalize to [0, 255]
40
  return generated_img
41
 
 
 
 
 
 
42
  # Custom CSS
43
  combined_css = """
44
  .main, .sidebar .sidebar-content { background-color: #1c1c1c; color: #f0f2f6; }
@@ -82,15 +88,24 @@ st.set_page_config(layout="wide")
82
 
83
  st.markdown(f"<style>{combined_css}</style>", unsafe_allow_html=True)
84
 
85
- st.markdown('<div class="title"><span class="colorful-text">Photo</span> <span class="black-white-text">to Art</span></div>', unsafe_allow_html=True)
86
- st.markdown('<div class="custom-text">Convert Photos to Art using CycleGAN</div>', unsafe_allow_html=True)
87
 
88
  # Streamlit UI
89
  uploaded_file = st.file_uploader("Choose an image...", type="jpg")
 
90
 
 
91
  if uploaded_file is not None:
92
- # Load and display the uploaded image
93
  image = Image.open(uploaded_file)
 
 
 
 
 
 
 
 
94
 
95
  if st.button("Run Inference"):
96
  # Perform inference
 
5
  from huggingface_hub import HfApi, hf_hub_download
6
  from PIL import Image
7
  from io import BytesIO
8
+ import requests
9
 
10
  # Hugging Face credentials
11
  api = HfApi()
 
40
  generated_img = (generated_img * 127.5 + 127.5).numpy().astype(np.uint8) # De-normalize to [0, 255]
41
  return generated_img
42
 
43
+ def load_image_from_url(url):
44
+ response = requests.get(url)
45
+ img = Image.open(BytesIO(response.content))
46
+ return img
47
+
48
  # Custom CSS
49
  combined_css = """
50
  .main, .sidebar .sidebar-content { background-color: #1c1c1c; color: #f0f2f6; }
 
88
 
89
  st.markdown(f"<style>{combined_css}</style>", unsafe_allow_html=True)
90
 
91
+ st.markdown('<div class="title"><span class="colorful-text">Photo</span> <span class="black-white-text">to Van Gogh</span></div>', unsafe_allow_html=True)
92
+ st.markdown('<div class="custom-text">Convert photos to Van Gogh style using AI</div>', unsafe_allow_html=True)
93
 
94
  # Streamlit UI
95
  uploaded_file = st.file_uploader("Choose an image...", type="jpg")
96
+ image_url = st.text_input("Or enter an image URL:")
97
 
98
+ image = None
99
  if uploaded_file is not None:
 
100
  image = Image.open(uploaded_file)
101
+ elif image_url:
102
+ try:
103
+ image = load_image_from_url(image_url)
104
+ except Exception as e:
105
+ st.error(f"Failed to load image from URL: {e}")
106
+
107
+ if image is not None:
108
+ st.image(image, caption='Original Image', use_column_width=True)
109
 
110
  if st.button("Run Inference"):
111
  # Perform inference