lgaleana commited on
Commit
55d5517
1 Parent(s): 28e7d81

Final gradio app

Browse files
Files changed (2) hide show
  1. ai_tasks/headlines_for_images.py +10 -4
  2. gradio_app.py +17 -3
ai_tasks/headlines_for_images.py CHANGED
@@ -1,3 +1,5 @@
 
 
1
  from typing import Dict, List
2
 
3
  from ai import llm
@@ -21,10 +23,14 @@ Dimensions for the ad: {dimensions}.
21
 
22
  Use the following format.
23
 
24
- Why the image was chosen:
25
- Url:
26
- Headline:
27
- Original dimensions:
 
 
 
 
28
  """
29
 
30
 
 
1
+ import json
2
+ import re
3
  from typing import Dict, List
4
 
5
  from ai import llm
 
23
 
24
  Use the following format.
25
 
26
+ ```
27
+ {{
28
+ "reason": Why the image was chosen
29
+ "url":
30
+ "headline"":
31
+ "original_domensions": The image's dimensions
32
+ }}
33
+ ```
34
  """
35
 
36
 
gradio_app.py CHANGED
@@ -55,12 +55,20 @@ def get_headline_for_image(prompt, url, dimensions, text, images, image_infos, s
55
  )
56
 
57
 
 
 
 
 
 
 
58
  with gr.Blocks() as demo:
59
  gr.Markdown(
60
  """
61
- ## Ad Generator
62
- Enter an url and the dimensions for an image (eg, 300x600) and get the image and headline for an ad."""
 
63
  )
 
64
 
65
  url = gr.Textbox(label="Input: {url}")
66
  dimensions = gr.Textbox(label="Input: {dimensions}")
@@ -132,14 +140,16 @@ with gr.Blocks() as demo:
132
  ai_tasks.headlines_for_images.PROMPT,
133
  label="Instructions",
134
  interactive=True,
 
135
  )
136
  with gr.Column():
137
  headline = gr.Textbox(
138
  label="Output: {headline}",
139
- lines=20,
140
  max_lines=10,
141
  interactive=False,
142
  )
 
143
 
144
  vars_ = [url, dimensions, text, images, image_infos, summary]
145
 
@@ -157,6 +167,10 @@ with gr.Blocks() as demo:
157
  get_headline_for_image,
158
  inputs=[headline_prompt] + vars_, # type: ignore
159
  outputs=[headline],
 
 
 
 
160
  )
161
 
162
  demo.launch()
 
55
  )
56
 
57
 
58
+ def set_image(headline):
59
+ import json
60
+
61
+ return json.loads(headline)["url"]
62
+
63
+
64
  with gr.Blocks() as demo:
65
  gr.Markdown(
66
  """
67
+ ## Scrape a website and get an ad
68
+ Enter an url and the dimensions for an image (eg, 300x600) and get an image from the website and the headline for an ad.
69
+ """
70
  )
71
+ gr.Markdown("Edit the AI tasks at your convenience.")
72
 
73
  url = gr.Textbox(label="Input: {url}")
74
  dimensions = gr.Textbox(label="Input: {dimensions}")
 
140
  ai_tasks.headlines_for_images.PROMPT,
141
  label="Instructions",
142
  interactive=True,
143
+ lines=20,
144
  )
145
  with gr.Column():
146
  headline = gr.Textbox(
147
  label="Output: {headline}",
148
+ lines=10,
149
  max_lines=10,
150
  interactive=False,
151
  )
152
+ headline_image = gr.Image()
153
 
154
  vars_ = [url, dimensions, text, images, image_infos, summary]
155
 
 
167
  get_headline_for_image,
168
  inputs=[headline_prompt] + vars_, # type: ignore
169
  outputs=[headline],
170
+ ).success(
171
+ set_image,
172
+ inputs=[headline],
173
+ outputs=[headline_image],
174
  )
175
 
176
  demo.launch()