Spaces:
Sleeping
Sleeping
| import streamlit as st | |
| from PIL import Image | |
| import numpy as np | |
| import plotly.graph_objects as go | |
| from transformers import pipeline # Hugging Face's pipeline API, optional | |
| # Streamlit App Configuration | |
| st.title("3D Image Converter") | |
| st.sidebar.header("Upload Image") | |
| # Upload Image | |
| uploaded_file = st.sidebar.file_uploader("Choose an image", type=["png", "jpg", "jpeg"]) | |
| if uploaded_file is not None: | |
| # Load Image | |
| image = Image.open(uploaded_file) | |
| st.image(image, caption="Uploaded Image", use_column_width=True) | |
| # Convert Image to Grayscale for Simplicity | |
| grayscale_image = image.convert("L") | |
| # Create 3D Surface Plot | |
| z_data = np.asarray(grayscale_image) | |
| x_data, y_data = np.meshgrid(range(z_data.shape[1]), range(z_data.shape[0])) | |
| # Create a 3D Surface Plot using Plotly | |
| fig = go.Figure(data=[go.Surface(z=z_data, x=x_data, y=y_data, colorscale='gray')]) | |
| fig.update_layout(scene=dict(zaxis=dict(title='Height'), | |
| xaxis=dict(title='Width'), | |
| yaxis=dict(title='Depth')), | |
| title="3D Representation of Image") | |
| st.plotly_chart(fig) | |
| # Option to Save 3D Data | |
| save_button = st.sidebar.button("Save 3D Data") | |
| if save_button: | |
| np.save("3d_image_data.npy", z_data) | |
| st.sidebar.success("3D data saved as 3d_image_data.npy!") | |
| # Optional: Integrate Hugging Face models for advanced transformations | |
| if st.sidebar.checkbox("Apply Hugging Face Transformation"): | |
| st.sidebar.text("Using Transformers API...") | |
| model = pipeline("image-to-image", model="stabilityai/stable-diffusion") # Replace with appropriate Hugging Face model | |
| result = model(uploaded_file) | |
| st.image(result["output_image"], caption="Transformed Image", use_column_width=True) | |
| # Note: | |
| # Ensure all dependencies are listed in requirements.txt for deployment. | |