valhalla commited on
Commit
a08f0b2
1 Parent(s): aff2150

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +0 -134
app.py CHANGED
@@ -1,141 +1,7 @@
1
- import os
2
- import sys
3
 
4
- #import numpy as np
5
  import streamlit as st
6
- #from PIL import Image
7
-
8
- # import clip
9
-
10
-
11
- # sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
12
-
13
- # import gradio as gr
14
- # from dalle.models import Dalle
15
- # from dalle.utils.utils import clip_score, set_seed
16
-
17
-
18
- device = "cpu"
19
- # model = Dalle.from_pretrained("minDALL-E/1.3B") # This will automatically download the pretrained model.
20
- # model.to(device=device)
21
-
22
- # model_clip, preprocess_clip = clip.load("ViT-B/32", device=device)
23
- # model_clip.to(device=device)
24
-
25
-
26
- # def sample(prompt):
27
- # # Sampling
28
- # images = (
29
- # model.sampling(prompt=prompt, top_k=256, top_p=None, softmax_temperature=1.0, num_candidates=3, device=device)
30
- # .cpu()
31
- # .numpy()
32
- # )
33
- # images = np.transpose(images, (0, 2, 3, 1))
34
-
35
- # # CLIP Re-ranking
36
- # rank = clip_score(
37
- # prompt=prompt, images=images, model_clip=model_clip, preprocess_clip=preprocess_clip, device=device
38
- # )
39
-
40
- # # Save images
41
- # images = images[rank]
42
- # # print(rank, images.shape)
43
- # pil_images = []
44
- # for i in range(len(images)):
45
- # im = Image.fromarray((images[i] * 255).astype(np.uint8))
46
- # pil_images.append(im)
47
-
48
- # # im = Image.fromarray((images[0] * 255).astype(np.uint8))
49
- # return pil_images
50
-
51
-
52
- # title = "Interactive demo: ImageGPT"
53
- # description = "Demo for OpenAI's ImageGPT: Generative Pretraining from Pixels. To use it, simply upload an image or use the example image below and click 'submit'. Results will show up in a few seconds."
54
- # article = "<p style='text-align: center'><a href='https://arxiv.org/abs/2109.10282'>ImageGPT: Generative Pretraining from Pixels</a> | <a href='https://openai.com/blog/image-gpt/'>Official blog</a></p>"
55
-
56
- # iface = gr.Interface(
57
- # fn=sample,
58
- # inputs=[gr.inputs.Textbox(label="What would you like to see?")],
59
- # outputs=gr.outputs.Image(type="pil", label="Model input + completions"),
60
- # title=title,
61
- # description=description,
62
- # article=article,
63
- # #examples=examples,
64
- # enable_queue=True,
65
- # )
66
- # iface.launch(debug=True)
67
-
68
- #!/usr/bin/env python
69
- # coding: utf-8
70
-
71
-
72
- st.sidebar.markdown(
73
- """
74
- <style>
75
- .aligncenter {
76
- text-align: center;
77
- }
78
- </style>
79
- <p class="aligncenter">
80
- <img src="https://raw.githubusercontent.com/borisdayma/dalle-mini/main/img/logo.png"/>
81
- </p>
82
- """,
83
- unsafe_allow_html=True,
84
- )
85
- st.sidebar.markdown(
86
- """
87
- ___
88
- <p style='text-align: center'>
89
- DALL·E mini is an AI model that generates images from any prompt you give!
90
- </p>
91
-
92
- <p style='text-align: center'>
93
- Created by Boris Dayma et al. 2021
94
- <br/>
95
- <a href="https://github.com/borisdayma/dalle-mini" target="_blank">GitHub</a> | <a href="https://wandb.ai/dalle-mini/dalle-mini/reports/DALL-E-mini--Vmlldzo4NjIxODA" target="_blank">Project Report</a>
96
- </p>
97
- """,
98
- unsafe_allow_html=True,
99
- )
100
 
101
  st.header("DALL·E mini")
102
  st.subheader("Generate images from text")
103
 
104
  prompt = st.text_input("What do you want to see?")
105
-
106
- DEBUG = False
107
- # if prompt != "":
108
- # container = st.empty()
109
- # container.markdown(
110
- # f"""
111
- # <style> p {{ margin:0 }} div {{ margin:0 }} </style>
112
- # <div data-stale="false" class="element-container css-1e5imcs e1tzin5v1">
113
- # <div class="stAlert">
114
- # <div role="alert" data-baseweb="notification" class="st-ae st-af st-ag st-ah st-ai st-aj st-ak st-g3 st-am st-b8 st-ao st-ap st-aq st-ar st-as st-at st-au st-av st-aw st-ax st-ay st-az st-b9 st-b1 st-b2 st-b3 st-b4 st-b5 st-b6">
115
- # <div class="st-b7">
116
- # <div class="css-whx05o e13vu3m50">
117
- # <div data-testid="stMarkdownContainer" class="css-1ekf893 e16nr0p30">
118
- # <img src="https://raw.githubusercontent.com/borisdayma/dalle-mini/main/app/streamlit/img/loading.gif" width="30"/>
119
- # Generating predictions for: <b>{prompt}</b>
120
- # </div>
121
- # </div>
122
- # </div>
123
- # </div>
124
- # </div>
125
- # </div>
126
- # <small><i>Predictions may take up to 40s under high load. Please stand by.</i></small>
127
- # """,
128
- # unsafe_allow_html=True,
129
- # )
130
-
131
- # print(f"Getting selections: {prompt}")
132
- # selected = sample(prompt)
133
-
134
- # margin = 0.1 # for better position of zoom in arrow
135
- # n_columns = 3
136
- # cols = st.columns([1] + [margin, 1] * (n_columns - 1))
137
- # for i, img in enumerate(selected):
138
- # cols[(i % n_columns) * 2].image(img)
139
- # container.markdown(f"**{prompt}**")
140
-
141
- # st.button("Again!", key="again_button")
 
 
 
1
 
 
2
  import streamlit as st
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3
 
4
  st.header("DALL·E mini")
5
  st.subheader("Generate images from text")
6
 
7
  prompt = st.text_input("What do you want to see?")