Hammad712 commited on
Commit
60994cc
·
verified ·
1 Parent(s): a124ac7

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +62 -3
app.py CHANGED
@@ -39,9 +39,53 @@ 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
- # Streamlit UI
43
- st.title("CycleGAN Inference App")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
44
 
 
45
  uploaded_file = st.file_uploader("Choose an image...", type="jpg")
46
 
47
  if uploaded_file is not None:
@@ -51,7 +95,22 @@ if uploaded_file is not None:
51
 
52
  if st.button("Run Inference"):
53
  # Perform inference
54
- generated_image = infer_image(loaded_model, image)
 
55
 
56
  # Display the result
57
  st.image(generated_image, caption='Generated Image', use_column_width=True)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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; }
45
+ .block-container { padding: 1rem 2rem; background-color: #333; border-radius: 10px; box-shadow: 0px 4px 10px rgba(0, 0, 0, 0.5); }
46
+ .stButton>button, .stDownloadButton>button { background: linear-gradient(135deg, #ff7e5f, #feb47b); color: white; border: none; padding: 10px 24px; text-align: center; text-decoration: none; display: inline-block; font-size: 16px; margin: 4px 2px; cursor: pointer; border-radius: 5px; }
47
+ .stSpinner { color: #4CAF50; }
48
+ .title {
49
+ font-size: 3rem;
50
+ font-weight: bold;
51
+ display: flex;
52
+ align-items: center;
53
+ justify-content: center;
54
+ }
55
+ .colorful-text {
56
+ background: -webkit-linear-gradient(135deg, #ff7e5f, #feb47b);
57
+ -webkit-background-clip: text;
58
+ -webkit-text-fill-color: transparent;
59
+ }
60
+ .black-white-text {
61
+ color: black;
62
+ }
63
+ .small-input .stTextInput>div>input {
64
+ height: 2rem;
65
+ font-size: 0.9rem;
66
+ }
67
+ .small-file-uploader .stFileUploader>div>div {
68
+ height: 2rem;
69
+ font-size: 0.9rem;
70
+ }
71
+ .custom-text {
72
+ font-size: 1.2rem;
73
+ color: #feb47b;
74
+ text-align: center;
75
+ margin-top: -20px;
76
+ margin-bottom: 20px;
77
+ }
78
+ """
79
+
80
+ # Streamlit application
81
+ 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">CycleGAN</span> <span class="black-white-text">Inference App</span></div>', unsafe_allow_html=True)
86
+ st.markdown('<div class="custom-text">Convert your images 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:
 
95
 
96
  if st.button("Run Inference"):
97
  # Perform inference
98
+ with st.spinner('Processing...'):
99
+ generated_image = infer_image(loaded_model, image)
100
 
101
  # Display the result
102
  st.image(generated_image, caption='Generated Image', use_column_width=True)
103
+
104
+ # Provide a download button for the generated image
105
+ img_byte_arr = BytesIO()
106
+ Image.fromarray(generated_image).save(img_byte_arr, format='JPEG')
107
+ img_byte_arr = img_byte_arr.getvalue()
108
+
109
+ st.download_button(
110
+ label="Download Generated Image",
111
+ data=img_byte_arr,
112
+ file_name="generated_image.jpg",
113
+ mime="image/jpeg"
114
+ )
115
+
116
+ st.success("Image processed successfully!")