|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
from diffusers import StableDiffusionPipeline |
|
|
import torch |
|
|
import streamlit as st |
|
|
|
|
|
def pic_mo(prom): |
|
|
model_id = "runwayml/stable-diffusion-v1-5" |
|
|
pipe = StableDiffusionPipeline.from_pretrained(model_id, torch_dtype=torch.float32) |
|
|
|
|
|
|
|
|
prompt = str(prom) |
|
|
|
|
|
image = pipe(prompt).images[0] |
|
|
|
|
|
return image |
|
|
|
|
|
|
|
|
def main(): |
|
|
st.title("Text to Image with runwayml/stable-diffusion-v1-5") |
|
|
|
|
|
|
|
|
title = st.text_input('Write a prompt (จะใช้เวลาค่อนข้างมากในการสร้างภาพเนื่องจากใช้ CPU ในการรันโมเดล)', "") |
|
|
|
|
|
if st.button('Generate Image'): |
|
|
|
|
|
generated_image = pic_mo(title) |
|
|
|
|
|
|
|
|
st.image(generated_image, caption='Generated Image', use_column_width=True) |
|
|
|
|
|
if __name__ == '__main__': |
|
|
main() |