|
|
|
import streamlit as st |
|
from generate import generate_image |
|
import os |
|
|
|
|
|
st.set_page_config(page_title="Visual Reconstruction from Brain", layout="centered") |
|
|
|
|
|
import streamlit.web.cli as stcli |
|
import sys |
|
sys.argv = ["streamlit", "run", "scripts/app.py", "--server.address", "10.192.12.247", "--server.port", "8501", "--browser.serverAddress", "10.192.12.247"] |
|
|
|
st.title("🧠 Imagine an Image!") |
|
|
|
|
|
sub = st.selectbox("Select Subject", options=[1, 2, 5, 7], index=0) |
|
|
|
|
|
image_id = st.number_input("Enter Image ID", min_value=0, step=1) |
|
|
|
original_path = f'data/nsddata_stimuli/test_images/{image_id}.png' |
|
if os.path.exists(original_path): |
|
st.image(original_path, caption="Original Image", use_column_width=True) |
|
else: |
|
st.warning("Original image not found.") |
|
|
|
annot = st.text_input("Describe what you imagined", placeholder="e.g., a dog under a tree") |
|
|
|
|
|
strength = st.slider("Diffusion Strength", 0.0, 1.0, 0.75, 0.05) |
|
mixing = st.slider("Mixing Strength", 0.0, 1.0, 0.4, 0.05) |
|
|
|
|
|
if st.button("Reconstruct Image"): |
|
with st.spinner("Reconstructing... please wait"): |
|
try: |
|
original_path, imagined_path = generate_image(sub, image_id, annot, strength, mixing) |
|
|
|
|
|
|
|
|
|
if os.path.exists(imagined_path): |
|
st.image(imagined_path, caption="Imagined Reconstruction", use_column_width=True) |
|
else: |
|
st.warning("Imagined image not found.") |
|
except Exception as e: |
|
st.error(f"⚠️ Error during generation: {e}") |
|
|
|
|
|
st.markdown("---") |
|
|