Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,25 +1,31 @@
|
|
| 1 |
import streamlit as st
|
| 2 |
-
from
|
| 3 |
import torch
|
| 4 |
-
from
|
| 5 |
-
from
|
| 6 |
|
| 7 |
-
# Load
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
device = "cpu"
|
| 12 |
-
pipe = StableDiffusionPipeline.from_pretrained(model_id, use_auth_token=True)
|
| 13 |
-
pipe.to(device)
|
| 14 |
-
return pipe
|
| 15 |
|
| 16 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 17 |
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
|
|
|
| 21 |
|
| 22 |
if st.button("Generate Image"):
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
import streamlit as st
|
| 2 |
+
from PIL import Image
|
| 3 |
import torch
|
| 4 |
+
from torchvision import transforms
|
| 5 |
+
from your_model_library import YourModel # Replace with actual model import
|
| 6 |
|
| 7 |
+
# Load your lightweight model
|
| 8 |
+
model = YourModel()
|
| 9 |
+
model.load_state_dict(torch.load('path_to_model_weights.pth', map_location=torch.device('cpu')))
|
| 10 |
+
model.eval()
|
|
|
|
|
|
|
|
|
|
|
|
|
| 11 |
|
| 12 |
+
# Define image transformation
|
| 13 |
+
transform = transforms.Compose([
|
| 14 |
+
transforms.Resize((256, 256)),
|
| 15 |
+
transforms.ToTensor(),
|
| 16 |
+
])
|
| 17 |
|
| 18 |
+
st.title("Text-to-Image Generator")
|
| 19 |
+
|
| 20 |
+
# Input text prompt
|
| 21 |
+
prompt = st.text_input("Enter a text prompt:")
|
| 22 |
|
| 23 |
if st.button("Generate Image"):
|
| 24 |
+
if prompt:
|
| 25 |
+
with torch.no_grad():
|
| 26 |
+
# Generate image from text prompt
|
| 27 |
+
generated_image = model.generate(prompt) # Replace with actual generation method
|
| 28 |
+
generated_image = transform(generated_image).unsqueeze(0)
|
| 29 |
+
st.image(generated_image.squeeze().permute(1, 2, 0).numpy(), caption="Generated Image")
|
| 30 |
+
else:
|
| 31 |
+
st.warning("Please enter a text prompt.")
|