Cari file su "/"
This commit is contained in:
parent
144baf1c85
commit
6c9e127bdc
2 changed files with 159 additions and 0 deletions
35
temp.py
Normal file
35
temp.py
Normal file
|
@ -0,0 +1,35 @@
|
|||
import torch
|
||||
from diffusers import StableDiffusionImg2ImgPipeline
|
||||
from PIL import Image
|
||||
import requests
|
||||
from io import BytesIO
|
||||
|
||||
# Load the pipeline
|
||||
pipe = StableDiffusionImg2ImgPipeline.from_pretrained(
|
||||
"runwayml/stable-diffusion-v1-5",
|
||||
torch_dtype=torch.float16,
|
||||
).to("cuda" if torch.cuda.is_available() else "cpu")
|
||||
|
||||
# Function to load image from local path or URL
|
||||
def load_image(path_or_url):
|
||||
if path_or_url.startswith("http"):
|
||||
response = requests.get(path_or_url)
|
||||
return Image.open(BytesIO(response.content)).convert("RGB")
|
||||
else:
|
||||
return Image.open(path_or_url).convert("RGB")
|
||||
|
||||
# Load original plant image
|
||||
input_image = st.file_uploader("Upload an image of your plant", type=["jpg", "jpeg", "png"])
|
||||
|
||||
# Resize to 512x512 for best results
|
||||
input_image = input_image.resize((512, 512))
|
||||
|
||||
# Define environmental condition prompt
|
||||
prompt = "A withered plant with brown leaves, dry soil, and signs of dehydration, after 10 days of heat and no water"
|
||||
|
||||
# Generate the modified image
|
||||
output = pipe(prompt=prompt, image=input_image, strength=0.75, guidance_scale=7.5)
|
||||
output_image = output.images[0]
|
||||
|
||||
# Save the result
|
||||
output_image.save("plant_future_prediction.png")
|
Loading…
Add table
Add a link
Reference in a new issue