Ghmustafa11 commited on
Commit
860ffd1
·
verified ·
1 Parent(s): 8eb7bc1

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +55 -0
app.py ADDED
@@ -0,0 +1,55 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Install necessary libraries
2
+ !pip install streamlit plotly transformers
3
+
4
+ # Import libraries
5
+ import streamlit as st
6
+ from PIL import Image
7
+ import numpy as np
8
+ import plotly.graph_objects as go
9
+ from transformers import pipeline # Hugging Face's pipeline API, optional
10
+
11
+ # Streamlit App Configuration
12
+ st.title("3D Image Converter")
13
+ st.sidebar.header("Upload Image")
14
+
15
+ # Upload Image
16
+ uploaded_file = st.sidebar.file_uploader("Choose an image", type=["png", "jpg", "jpeg"])
17
+
18
+ if uploaded_file is not None:
19
+ # Load Image
20
+ image = Image.open(uploaded_file)
21
+ st.image(image, caption="Uploaded Image", use_column_width=True)
22
+
23
+ # Convert Image to Grayscale for Simplicity
24
+ grayscale_image = image.convert("L")
25
+
26
+ # Create 3D Surface Plot
27
+ z_data = np.asarray(grayscale_image)
28
+ x_data, y_data = np.meshgrid(range(z_data.shape[1]), range(z_data.shape[0]))
29
+
30
+ # Create a 3D Surface Plot using Plotly
31
+ fig = go.Figure(data=[go.Surface(z=z_data, x=x_data, y=y_data, colorscale='gray')])
32
+ fig.update_layout(scene=dict(zaxis=dict(title='Height'),
33
+ xaxis=dict(title='Width'),
34
+ yaxis=dict(title='Depth')),
35
+ title="3D Representation of Image")
36
+
37
+ st.plotly_chart(fig)
38
+
39
+ # Option to Save 3D Data
40
+ save_button = st.sidebar.button("Save 3D Data")
41
+ if save_button:
42
+ np.save("3d_image_data.npy", z_data)
43
+ st.sidebar.success("3D data saved as 3d_image_data.npy!")
44
+
45
+ # Optional: Integrate Hugging Face models for advanced transformations
46
+ if st.sidebar.checkbox("Apply Hugging Face Transformation"):
47
+ st.sidebar.text("Using Transformers API...")
48
+ model = pipeline("image-to-image", model="stabilityai/stable-diffusion") # Replace with appropriate Hugging Face model
49
+ result = model(uploaded_file)
50
+ st.image(result["output_image"], caption="Transformed Image", use_column_width=True)
51
+
52
+ # Note for Colab users:
53
+ # Streamlit applications are designed to run locally. Use the command below in a Colab cell to launch the app:
54
+ # !streamlit run your_script_name.py
55
+ # After running the command, Colab will provide a public URL to access the Streamlit app.