Hammad712 commited on
Commit
39283bd
·
verified ·
1 Parent(s): f877448

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +25 -4
app.py CHANGED
@@ -75,7 +75,8 @@ def inference(image_path_or_url, learn):
75
  return tensor_to_pil(img_hr)
76
 
77
  # Streamlit application
78
- st.title("Image Inference with Fastai")
 
79
 
80
  # Download the model file from the Hugging Face repository
81
  model_url = "https://huggingface.co/Hammad712/image2sketch/resolve/main/image2sketch.pkl"
@@ -93,14 +94,34 @@ with tempfile.TemporaryDirectory() as tmpdirname:
93
  shutil.move(model_file_path, os.path.join(tmpdirname, 'export.pkl'))
94
  learn = load_learner(tmpdirname)
95
 
 
 
 
 
 
 
 
 
96
  # Input for image URL or path
97
- image_path_or_url = st.text_input("Enter image path or URL", "")
98
 
99
  # Run inference button
100
- if st.button("Run Inference"):
101
  if image_path_or_url:
102
  with st.spinner('Processing...'):
103
  high_res_image = inference(image_path_or_url, learn)
104
- st.image(high_res_image, caption='High Resolution Image', use_column_width=True)
 
 
 
 
 
 
 
 
 
 
 
 
105
  else:
106
  st.error("Please enter a valid image path or URL.")
 
75
  return tensor_to_pil(img_hr)
76
 
77
  # Streamlit application
78
+ st.title("Image to Sketch")
79
+ st.write("Convert any image to its sketch version using a Pix2Pix GAN Model.")
80
 
81
  # Download the model file from the Hugging Face repository
82
  model_url = "https://huggingface.co/Hammad712/image2sketch/resolve/main/image2sketch.pkl"
 
94
  shutil.move(model_file_path, os.path.join(tmpdirname, 'export.pkl'))
95
  learn = load_learner(tmpdirname)
96
 
97
+ # Sidebar to display previous generated images
98
+ st.sidebar.title("Previous Results")
99
+ if 'generated_images' not in st.session_state:
100
+ st.session_state['generated_images'] = []
101
+
102
+ for img in st.session_state['generated_images']:
103
+ st.sidebar.image(img, use_column_width=True)
104
+
105
  # Input for image URL or path
106
+ image_path_or_url = st.text_input("Enter image URL", "")
107
 
108
  # Run inference button
109
+ if st.button("Convert"):
110
  if image_path_or_url:
111
  with st.spinner('Processing...'):
112
  high_res_image = inference(image_path_or_url, learn)
113
+ original_image = PIL.Image.open(BytesIO(requests.get(image_path_or_url).content)) if image_path_or_url.startswith('http') else PIL.Image.open(image_path_or_url)
114
+
115
+ # Display original and high-res images side by side
116
+ col1, col2 = st.columns(2)
117
+
118
+ with col1:
119
+ st.image(original_image, caption='Original Image', use_column_width=True)
120
+ with col2:
121
+ st.image(high_res_image, caption='Sketch Image', use_column_width=True)
122
+
123
+ # Save the generated image to session state for sidebar display
124
+ st.session_state['generated_images'].append(high_res_image)
125
+
126
  else:
127
  st.error("Please enter a valid image path or URL.")