Update app.py
Browse files
app.py
CHANGED
@@ -110,7 +110,18 @@ css = """
|
|
110 |
height: 500px;
|
111 |
overflow: auto;
|
112 |
border: 1px solid #ccc;
|
113 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
114 |
|
115 |
with gr.Blocks(css=css) as demo:
|
116 |
gr.Markdown("<h1>WordLift Product Description Generation - [FREE]</h1>")
|
@@ -169,12 +180,51 @@ with gr.Blocks(css=css) as demo:
|
|
169 |
outputs=[custom_instruction],
|
170 |
)
|
171 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
172 |
submit_btn.click(
|
173 |
-
|
174 |
-
[input_img, description_type, custom_instruction],
|
175 |
-
[output_text],
|
176 |
)
|
177 |
|
|
|
|
|
|
|
|
|
178 |
# Launch Gradio app
|
179 |
demo.queue(api_open=False)
|
180 |
demo.launch(debug=True)
|
|
|
110 |
height: 500px;
|
111 |
overflow: auto;
|
112 |
border: 1px solid #ccc;
|
113 |
+
}
|
114 |
+
.redirect-message {
|
115 |
+
background-color: #f0f0f0;
|
116 |
+
border: 1px solid #ccc;
|
117 |
+
padding: 15px;
|
118 |
+
margin-top: 20px;
|
119 |
+
border-radius: 5px;
|
120 |
+
}
|
121 |
+
"""
|
122 |
+
|
123 |
+
# Initialize the test counter
|
124 |
+
test_counter = 0
|
125 |
|
126 |
with gr.Blocks(css=css) as demo:
|
127 |
gr.Markdown("<h1>WordLift Product Description Generation - [FREE]</h1>")
|
|
|
180 |
outputs=[custom_instruction],
|
181 |
)
|
182 |
|
183 |
+
# Modified function to handle test limit
|
184 |
+
def handle_submit(image, description_type, custom_instruction):
|
185 |
+
global test_counter
|
186 |
+
if test_counter < 4:
|
187 |
+
test_counter += 1
|
188 |
+
result = generate_product_description(image, description_type, custom_instruction)
|
189 |
+
remaining_tests = 4 - test_counter
|
190 |
+
if remaining_tests > 0:
|
191 |
+
return (
|
192 |
+
result,
|
193 |
+
gr.update(visible=False),
|
194 |
+
gr.update(interactive=True),
|
195 |
+
f"You have {remaining_tests} test(s) remaining.",
|
196 |
+
)
|
197 |
+
else:
|
198 |
+
redirect_text = """
|
199 |
+
You've reached the limit of 4 free tests. To continue using our product description generation tool,
|
200 |
+
please book a demo of our solution for content generation with our experts.
|
201 |
+
|
202 |
+
[Book a Demo](https://wordlift.io/book-a-demo/)
|
203 |
+
"""
|
204 |
+
return (
|
205 |
+
result,
|
206 |
+
gr.update(visible=True, value=redirect_text),
|
207 |
+
gr.update(interactive=False),
|
208 |
+
"You've used all your free tests.",
|
209 |
+
)
|
210 |
+
else:
|
211 |
+
return (
|
212 |
+
"",
|
213 |
+
gr.update(visible=True),
|
214 |
+
gr.update(interactive=False),
|
215 |
+
"You've used all your free tests.",
|
216 |
+
)
|
217 |
+
|
218 |
submit_btn.click(
|
219 |
+
handle_submit,
|
220 |
+
inputs=[input_img, description_type, custom_instruction],
|
221 |
+
outputs=[output_text, redirect_message, submit_btn, gr.Markdown(visible=True, label="Test Counter")],
|
222 |
)
|
223 |
|
224 |
+
# Launch Gradio app
|
225 |
+
demo.queue(api_open=False)
|
226 |
+
demo.launch(debug=True)
|
227 |
+
|
228 |
# Launch Gradio app
|
229 |
demo.queue(api_open=False)
|
230 |
demo.launch(debug=True)
|