File size: 1,179 Bytes
aec5ec6
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
import gradio as gr
import requests
from PIL import Image
from io import BytesIO

def fetch_compressed_image(image):
    # This is where you fetch the compressed image from the Streamlit app running on localhost:8501
    # For example, you might have an API endpoint in Streamlit that returns the compressed image
    # Example URL: http://localhost:8501/compress_image
    image = Image.fromarray(image)
    buf = BytesIO()
    image.save(buf, format="PNG")
    buf.seek(0)
    
    files = {"file": buf}
    response = requests.post("http://localhost:8501/compress_image", files=files)
    
    if response.status_code == 200:
        compressed_image = Image.open(BytesIO(response.content))
        return compressed_image
    else:
        return "Error: Unable to fetch compressed image."

# Gradio interface
gr_interface = gr.Interface(fn=fetch_compressed_image,
                            inputs="image",
                            outputs="image",
                            title="Interactive Image Compression using SVD",
                            description="Upload an image and see the compressed version processed by the Streamlit app.")

gr_interface.launch()