Spaces:
Paused
Paused
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# app.py for Hugging Face Space frontend
|
| 2 |
+
import requests
|
| 3 |
+
from PIL import Image
|
| 4 |
+
from io import BytesIO
|
| 5 |
+
import streamlit as st # HF Spaces supports Streamlit out of the box
|
| 6 |
+
|
| 7 |
+
# -----------------------------
|
| 8 |
+
# Config: Use your cloudflare URL
|
| 9 |
+
# -----------------------------
|
| 10 |
+
API_URL = "https://greensboro-scholar-under-voted.trycloudflare.com/predict"
|
| 11 |
+
|
| 12 |
+
st.title("Solar PV EL Image Segmentation")
|
| 13 |
+
|
| 14 |
+
uploaded_file = st.file_uploader("Upload an EL image", type=["png", "jpg", "jpeg"])
|
| 15 |
+
|
| 16 |
+
if uploaded_file is not None:
|
| 17 |
+
st.image(uploaded_file, caption="Input EL Image", use_column_width=True)
|
| 18 |
+
|
| 19 |
+
# Prepare image for POST
|
| 20 |
+
files = {"file": (uploaded_file.name, uploaded_file, "image/png")}
|
| 21 |
+
with st.spinner("Running segmentation..."):
|
| 22 |
+
response = requests.post(API_URL, files=files)
|
| 23 |
+
|
| 24 |
+
if response.status_code == 200:
|
| 25 |
+
# Read image from response
|
| 26 |
+
segmented_img = Image.open(BytesIO(response.content))
|
| 27 |
+
st.image(segmented_img, caption="Segmented Output", use_column_width=True)
|
| 28 |
+
else:
|
| 29 |
+
st.error(f"Segmentation failed! Status code: {response.status_code}")
|