Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,39 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# -*- coding: utf-8 -*-
|
2 |
+
|
3 |
+
#!pip install torch
|
4 |
+
|
5 |
+
#!pip install diffusers transformers accelerate torch
|
6 |
+
|
7 |
+
#!pip install streamlit
|
8 |
+
|
9 |
+
from diffusers import StableDiffusionPipeline
|
10 |
+
import torch
|
11 |
+
import streamlit as st
|
12 |
+
|
13 |
+
def pic_mo(prom):
|
14 |
+
model_id = "runwayml/stable-diffusion-v1-5"
|
15 |
+
pipe = StableDiffusionPipeline.from_pretrained(model_id, torch_dtype=torch.float32) # Change to float32
|
16 |
+
# No need ("cuda") if running on CPU because dont't have money
|
17 |
+
|
18 |
+
prompt = str(prom)
|
19 |
+
|
20 |
+
image = pipe(prompt).images[0]
|
21 |
+
|
22 |
+
return image
|
23 |
+
|
24 |
+
|
25 |
+
def main():
|
26 |
+
st.title("Text to Image with runwayml/stable-diffusion-v1-5")
|
27 |
+
|
28 |
+
# Input text prompt
|
29 |
+
title = st.text_input('Write a prompt (จะใช้เวลาค่อนข้างมากในการสร้างภาพเนื่องจากใช้ CPU ในการรันโมเดล)', "")
|
30 |
+
|
31 |
+
if st.button('Generate Image'):
|
32 |
+
# Call the pic_mo function to generate an image
|
33 |
+
generated_image = pic_mo(title)
|
34 |
+
|
35 |
+
# Display the generated image
|
36 |
+
st.image(generated_image, caption='Generated Image', use_column_width=True)
|
37 |
+
|
38 |
+
if __name__ == '__main__':
|
39 |
+
main()
|