Spaces:
Build error
Build error
soupstick
commited on
Commit
Β·
16fe8ec
1
Parent(s):
ea83c32
Fix: upgrade to resolve TypeError
Browse files- app.py +24 -58
- requirements.txt +2 -3
app.py
CHANGED
@@ -134,68 +134,34 @@ def format_example_output():
|
|
134 |
return json.dumps(example, indent=2)
|
135 |
|
136 |
# Gradio Interface
|
137 |
-
def create_interface():
|
138 |
-
|
139 |
-
|
140 |
-
|
141 |
-
|
142 |
-
|
143 |
-
|
144 |
-
|
145 |
-
""
|
146 |
-
|
147 |
-
|
148 |
-
|
149 |
-
|
150 |
-
|
151 |
-
|
152 |
-
|
153 |
-
|
154 |
-
|
155 |
-
|
156 |
-
|
157 |
-
placeholder="Enter custom instruction or use default",
|
158 |
-
lines=2
|
159 |
-
)
|
160 |
-
generate_btn = gr.Button(
|
161 |
-
"π Generate Listing",
|
162 |
-
variant="primary",
|
163 |
-
size="lg"
|
164 |
-
)
|
165 |
-
|
166 |
-
with gr.Column():
|
167 |
-
output_text = gr.Textbox(
|
168 |
-
label="π Generated Listing",
|
169 |
-
lines=15,
|
170 |
-
placeholder="Upload an image and click 'Generate Listing' to see results..."
|
171 |
-
)
|
172 |
-
|
173 |
-
# Example section
|
174 |
-
with gr.Accordion("π Expected Output Format", open=False):
|
175 |
-
gr.Code(
|
176 |
-
format_example_output(),
|
177 |
-
language="json",
|
178 |
-
label="Example JSON Structure"
|
179 |
-
)
|
180 |
-
|
181 |
-
# Event handler
|
182 |
-
generate_btn.click(
|
183 |
fn=generate_listing,
|
184 |
inputs=[image_input, prompt_input],
|
185 |
-
outputs=output_text
|
|
|
|
|
186 |
)
|
187 |
-
|
188 |
-
# Footer
|
189 |
-
gr.Markdown("""
|
190 |
-
---
|
191 |
-
**β οΈ Note**: This demo runs on CPU which may take 1-2 minutes per generation.
|
192 |
-
For faster inference, consider upgrading to GPU hardware.
|
193 |
-
|
194 |
-
**π Links**: [Model Card](https://huggingface.co/soupstick/qwen2vl-amazon-ft-lora) | [Base Model](https://huggingface.co/Qwen/Qwen2-VL-7B-Instruct)
|
195 |
-
""")
|
196 |
-
|
197 |
return demo
|
198 |
|
199 |
if __name__ == "__main__":
|
200 |
demo = create_interface()
|
201 |
-
demo.launch(share=True)
|
|
|
134 |
return json.dumps(example, indent=2)
|
135 |
|
136 |
# Gradio Interface
|
137 |
+
def create_interface():
|
138 |
+
if hasattr(gr, 'Blocks'):
|
139 |
+
# Preferred Blocks layout (with theme if available)
|
140 |
+
theme_obj = None
|
141 |
+
try:
|
142 |
+
theme_obj = gr.themes.Soft()
|
143 |
+
except Exception:
|
144 |
+
theme_obj = None
|
145 |
+
with gr.Blocks(theme=theme_obj, title="Amazon Listing Generator") as demo:
|
146 |
+
generate_btn.click(
|
147 |
+
fn=generate_listing,
|
148 |
+
inputs=[image_input, prompt_input],
|
149 |
+
outputs=output_text,
|
150 |
+
api_name=False)
|
151 |
+
else:
|
152 |
+
# Fallback: simple Interface if gr.Blocks is unavailable
|
153 |
+
image_input = gr.Image(type='pil', label='πΈ Upload Product Image', height=300, sources=['upload'])
|
154 |
+
prompt_input = gr.Textbox(label='π Instruction (Optional)', value='Generate Amazon listing.', lines=2)
|
155 |
+
output_text = gr.Textbox(label='π Generated Listing', lines=15)
|
156 |
+
demo = gr.Interface(
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
157 |
fn=generate_listing,
|
158 |
inputs=[image_input, prompt_input],
|
159 |
+
outputs=output_text,
|
160 |
+
title='Amazon Listing Generator',
|
161 |
+
description='Upload a product image and optionally an instruction to generate an Amazon listing.'
|
162 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
163 |
return demo
|
164 |
|
165 |
if __name__ == "__main__":
|
166 |
demo = create_interface()
|
167 |
+
demo.launch(share=True, show_api=False)
|
requirements.txt
CHANGED
@@ -1,6 +1,5 @@
|
|
1 |
-
|
2 |
-
gradio
|
3 |
-
gradio-client>=1.3.0
|
4 |
transformers>=4.44.0
|
5 |
peft>=0.10.0
|
6 |
accelerate>=0.24.0
|
|
|
1 |
+
gradio>=5.4.0,<6.0.0
|
2 |
+
gradio==4.44.0
|
|
|
3 |
transformers>=4.44.0
|
4 |
peft>=0.10.0
|
5 |
accelerate>=0.24.0
|