NaimaAqeel commited on
Commit
aec5ec6
·
verified ·
1 Parent(s): ed902b1

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +31 -0
app.py ADDED
@@ -0,0 +1,31 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import requests
3
+ from PIL import Image
4
+ from io import BytesIO
5
+
6
+ def fetch_compressed_image(image):
7
+ # This is where you fetch the compressed image from the Streamlit app running on localhost:8501
8
+ # For example, you might have an API endpoint in Streamlit that returns the compressed image
9
+ # Example URL: http://localhost:8501/compress_image
10
+ image = Image.fromarray(image)
11
+ buf = BytesIO()
12
+ image.save(buf, format="PNG")
13
+ buf.seek(0)
14
+
15
+ files = {"file": buf}
16
+ response = requests.post("http://localhost:8501/compress_image", files=files)
17
+
18
+ if response.status_code == 200:
19
+ compressed_image = Image.open(BytesIO(response.content))
20
+ return compressed_image
21
+ else:
22
+ return "Error: Unable to fetch compressed image."
23
+
24
+ # Gradio interface
25
+ gr_interface = gr.Interface(fn=fetch_compressed_image,
26
+ inputs="image",
27
+ outputs="image",
28
+ title="Interactive Image Compression using SVD",
29
+ description="Upload an image and see the compressed version processed by the Streamlit app.")
30
+
31
+ gr_interface.launch()