snehakingrani commited on
Commit
2381e5b
·
verified ·
1 Parent(s): 75dd342

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +14 -19
app.py CHANGED
@@ -2,30 +2,25 @@ 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.")
 
2
  from PIL import Image
3
  import torch
4
  from torchvision import transforms
5
+ from bk_sdm import BKSDMPipeline # Hypothetical import; replace with actual model import
6
 
7
+ # Initialize the model
8
+ @st.cache_resource
9
+ def load_model():
10
+ model = BKSDMPipeline.from_pretrained('path_to_bk_sdm_model')
11
+ return model
12
 
13
+ model = load_model()
 
 
 
 
14
 
15
+ # Streamlit app interface
16
+ st.title("Text-to-Image Generation")
 
17
  prompt = st.text_input("Enter a text prompt:")
18
 
19
  if st.button("Generate Image"):
20
  if prompt:
21
+ with st.spinner("Generating image..."):
22
+ # Generate image
23
+ image = model(prompt)
24
+ st.image(image, caption="Generated Image")
 
25
  else:
26
+ st.warning("Please enter a prompt.")