|
import gradio as gr |
|
import requests |
|
from PIL import Image |
|
from io import BytesIO |
|
|
|
def fetch_compressed_image(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." |
|
|
|
|
|
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() |