Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
|
@@ -126,23 +126,24 @@ with gr.Blocks() as demo:
|
|
| 126 |
with gr.Row():
|
| 127 |
with gr.Column(scale=1):
|
| 128 |
alt_key = gr.Textbox(label="Alternate Mistral API Key (optional)", type="password")
|
| 129 |
-
url_input = gr.Textbox(label="Image URL", placeholder="https://..."
|
| 130 |
custom = gr.Textbox(label="Custom prompt (optional)", lines=4, placeholder="Leave blank to use auto prompt")
|
| 131 |
auto_toggle = gr.Checkbox(label="Use detailed auto prompt", value=True)
|
| 132 |
-
with gr.Column(scale=1):
|
| 133 |
preview = gr.Image(label="Preview", type="pil")
|
|
|
|
|
|
|
| 134 |
out = gr.Textbox(label="Generated Detailed Description", lines=20)
|
| 135 |
|
| 136 |
-
def
|
| 137 |
if not url:
|
| 138 |
-
return None
|
| 139 |
try:
|
| 140 |
r = requests.get(url, timeout=30)
|
| 141 |
r.raise_for_status()
|
| 142 |
img = Image.open(BytesIO(r.content)).convert("RGB")
|
| 143 |
-
return img
|
| 144 |
except Exception:
|
| 145 |
-
return None
|
| 146 |
|
| 147 |
def start_gen(url, use_auto, custom_p, alt_k):
|
| 148 |
if not url:
|
|
@@ -150,8 +151,7 @@ with gr.Blocks() as demo:
|
|
| 150 |
for chunk in generate_stream(url, use_auto, custom_p, alt_k):
|
| 151 |
yield chunk
|
| 152 |
|
| 153 |
-
url_input.change(fn=
|
| 154 |
-
|
| 155 |
-
url_input.submit(fn=start_gen, inputs=[url_input, auto_toggle, custom, alt_key], outputs=[out])
|
| 156 |
|
| 157 |
demo.launch()
|
|
|
|
| 126 |
with gr.Row():
|
| 127 |
with gr.Column(scale=1):
|
| 128 |
alt_key = gr.Textbox(label="Alternate Mistral API Key (optional)", type="password")
|
| 129 |
+
url_input = gr.Textbox(label="Image URL", placeholder="https://...")
|
| 130 |
custom = gr.Textbox(label="Custom prompt (optional)", lines=4, placeholder="Leave blank to use auto prompt")
|
| 131 |
auto_toggle = gr.Checkbox(label="Use detailed auto prompt", value=True)
|
|
|
|
| 132 |
preview = gr.Image(label="Preview", type="pil")
|
| 133 |
+
submit = gr.Button("Submit")
|
| 134 |
+
with gr.Column(scale=1):
|
| 135 |
out = gr.Textbox(label="Generated Detailed Description", lines=20)
|
| 136 |
|
| 137 |
+
def load_preview(url):
|
| 138 |
if not url:
|
| 139 |
+
return None
|
| 140 |
try:
|
| 141 |
r = requests.get(url, timeout=30)
|
| 142 |
r.raise_for_status()
|
| 143 |
img = Image.open(BytesIO(r.content)).convert("RGB")
|
| 144 |
+
return img
|
| 145 |
except Exception:
|
| 146 |
+
return None
|
| 147 |
|
| 148 |
def start_gen(url, use_auto, custom_p, alt_k):
|
| 149 |
if not url:
|
|
|
|
| 151 |
for chunk in generate_stream(url, use_auto, custom_p, alt_k):
|
| 152 |
yield chunk
|
| 153 |
|
| 154 |
+
url_input.change(fn=load_preview, inputs=[url_input], outputs=[preview])
|
| 155 |
+
submit.click(fn=start_gen, inputs=[url_input, auto_toggle, custom, alt_key], outputs=[out])
|
|
|
|
| 156 |
|
| 157 |
demo.launch()
|