boris commited on
Commit
d4e833e
1 Parent(s): db7d521

feat: reorganize app

Browse files
README.md CHANGED
@@ -4,8 +4,8 @@ emoji: 🥑
4
  colorFrom: yellow
5
  colorTo: green
6
  sdk: streamlit
7
- app_file: app/app.py
8
- pinned: false
9
  ---
10
 
11
  # DALL·E Mini
 
4
  colorFrom: yellow
5
  colorTo: green
6
  sdk: streamlit
7
+ app_file: app/streamlit/app.py
8
+ pinned: True
9
  ---
10
 
11
  # DALL·E Mini
app/gradio/app_gradio_ngrok.py DELETED
@@ -1,89 +0,0 @@
1
- #!/usr/bin/env python
2
- # coding: utf-8
3
-
4
- import requests
5
- from PIL import Image
6
- import numpy as np
7
- import matplotlib.pyplot as plt
8
- from io import BytesIO
9
- import base64
10
- import os
11
-
12
- import gradio as gr
13
-
14
- from dalle_mini.helpers import captioned_strip
15
-
16
-
17
- backend_url = os.environ["BACKEND_SERVER"]
18
-
19
-
20
- class ServiceError(Exception):
21
- def __init__(self, status_code):
22
- self.status_code = status_code
23
-
24
- def get_images_from_ngrok(prompt):
25
- r = requests.post(
26
- backend_url,
27
- json={"prompt": prompt}
28
- )
29
- if r.status_code == 200:
30
- images = r.json()["images"]
31
- images = [Image.open(BytesIO(base64.b64decode(img))) for img in images]
32
- return images
33
- else:
34
- raise ServiceError(r.status_code)
35
-
36
- def run_inference(prompt):
37
- try:
38
- images = get_images_from_ngrok(prompt)
39
- predictions = captioned_strip(images)
40
- output_title = f"""
41
- <p style="font-size:22px; font-style:bold">Best predictions</p>
42
- <p>We asked our model to generate 128 candidates for your prompt:</p>
43
-
44
- <pre>
45
-
46
- <b>{prompt}</b>
47
- </pre>
48
- <p>We then used a pre-trained <a href="https://huggingface.co/openai/clip-vit-base-patch32">CLIP model</a> to score them according to the
49
- similarity of the text and the image representations.</p>
50
-
51
- <p>This is the result:</p>
52
- """
53
-
54
- output_description = """
55
- <p>Read our <a style="color:blue;" href="https://wandb.ai/dalle-mini/dalle-mini/reports/DALL-E-mini--Vmlldzo4NjIxODA">full report</a> for more details on how this works.<p>
56
- <p style='text-align: center'>Created with <a style="color:blue;" href="https://github.com/borisdayma/dalle-mini">DALL·E mini</a></p>
57
- """
58
-
59
- except ServiceError:
60
- output_title = f"""
61
- Sorry, there was an error retrieving the images. Please, try again later or <a href="mailto:pcuenca-dalle@guenever.net">contact us here</a>.
62
- """
63
- predictions = None
64
- output_description = ""
65
-
66
- return (output_title, predictions, output_description)
67
-
68
- outputs = [
69
- gr.outputs.HTML(label=""), # To be used as title
70
- gr.outputs.Image(label=''),
71
- gr.outputs.HTML(label=""), # Additional text that appears in the screenshot
72
- ]
73
-
74
- description = """
75
- Welcome to DALL·E-mini, a text-to-image generation model.
76
- """
77
- gr.Interface(run_inference,
78
- inputs=[gr.inputs.Textbox(label='Prompt')],
79
- outputs=outputs,
80
- title='DALL·E mini',
81
- description=description,
82
- article="<p style='text-align: center'> DALLE·mini by Boris Dayma et al. | <a href='https://github.com/borisdayma/dalle-mini'>GitHub</a></p>",
83
- layout='vertical',
84
- theme='huggingface',
85
- examples=[['an armchair in the shape of an avocado'], ['snowy mountains by the sea']],
86
- allow_flagging=False,
87
- live=False,
88
- # server_name="0.0.0.0", # Bind to all interfaces
89
- ).launch()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
app/{app.py → streamlit/app.py} RENAMED
@@ -1,7 +1,7 @@
1
  #!/usr/bin/env python
2
  # coding: utf-8
3
 
4
- from dalle_mini.backend import ServiceError, get_images_from_backend
5
  import streamlit as st
6
 
7
  st.sidebar.markdown(
@@ -50,7 +50,7 @@ if prompt != "":
50
  <div class="st-b7">
51
  <div class="css-whx05o e13vu3m50">
52
  <div data-testid="stMarkdownContainer" class="css-1ekf893 e16nr0p30">
53
- <img src="https://raw.githubusercontent.com/borisdayma/dalle-mini/main/app/img/loading.gif" width="30"/>
54
  Generating predictions for: <b>{prompt}</b>
55
  </div>
56
  </div>
 
1
  #!/usr/bin/env python
2
  # coding: utf-8
3
 
4
+ from .backend import ServiceError, get_images_from_backend
5
  import streamlit as st
6
 
7
  st.sidebar.markdown(
 
50
  <div class="st-b7">
51
  <div class="css-whx05o e13vu3m50">
52
  <div data-testid="stMarkdownContainer" class="css-1ekf893 e16nr0p30">
53
+ <img src="https://raw.githubusercontent.com/borisdayma/dalle-mini/main/app/streamlit/img/loading.gif" width="30"/>
54
  Generating predictions for: <b>{prompt}</b>
55
  </div>
56
  </div>
{dalle_mini → app/streamlit}/backend.py RENAMED
File without changes
app/{img → streamlit/img}/loading.gif RENAMED
File without changes