File size: 3,163 Bytes
61d360d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
import streamlit as st
import requests
import os
import sys
from PIL import Image
import io
import time
from pathlib import Path

# Set API URL
API_URL = "http://localhost:8001"  # Local FastAPI server URL

st.set_page_config(
    page_title="Image Deblurring App",
    page_icon="🔍",
    layout="wide",
)

st.title("Image Deblurring Application")
st.markdown("""
Turn your blurry photos into clear, sharp images using AI technology.
Upload an image to get started!
""")

# File uploader
uploaded_file = st.file_uploader(
    "Choose a blurry image...", type=["jpg", "jpeg", "png", "bmp"])

# Sidebar controls
with st.sidebar:
    st.header("Deblurring Options")
    
    # Additional options could be added here in the future
    st.markdown("This application uses a deep learning model to remove blur from images.")
    st.markdown("---")
    
    # Check API status
    if st.button("Check API Status"):
        try:
            response = requests.get(f"{API_URL}/status/", timeout=5)
            if response.status_code == 200 and response.json().get("status") == "ok":
                st.success("✅ API is running and ready")
            else:
                st.error("❌ API is not responding properly")
        except:
            st.error("❌ Cannot connect to API")

# Process when upload is ready
if uploaded_file is not None:
    # Display the original image
    col1, col2 = st.columns(2)

    with col1:
        st.subheader("Original Image")
        image = Image.open(uploaded_file)
        st.image(image, use_column_width=True)

    # Process image button
    process_button = st.button("Deblur Image")

    if process_button:
        with st.spinner("Deblurring your image... Please wait."):
            try:
                # Prepare simplified file structure
                files = {
                    "file": ("image.jpg", uploaded_file.getvalue(), "image/jpeg")
                }
                
                # Send request to API
                response = requests.post(f"{API_URL}/deblur/", files=files, timeout=60)

                if response.status_code == 200:
                    with col2:
                        st.subheader("Deblurred Result")
                        deblurred_img = Image.open(io.BytesIO(response.content))
                        st.image(deblurred_img, use_column_width=True)

                    # Option to download the deblurred image
                    st.download_button(
                        label="Download Deblurred Image",
                        data=response.content,
                        file_name=f"deblurred_{uploaded_file.name}",
                        mime="image/png"
                    )
                else:
                    try:
                        error_details = response.json().get('detail', 'Unknown error')
                    except:
                        error_details = response.text
                    
                    st.error(f"Error: {error_details}")
            except Exception as e:
                st.error(f"An error occurred: {str(e)}")

# Footer
st.markdown("---")
st.markdown("Powered by DeblurGAN - Image Restoration Project")