soupstick commited on
Commit
16fe8ec
Β·
1 Parent(s): ea83c32

Fix: upgrade to resolve TypeError

Browse files
Files changed (2) hide show
  1. app.py +24 -58
  2. 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
- with gr.Blocks(theme=gr.themes.Soft(), title="Amazon Listing Generator") as demo:
139
- gr.Markdown("""
140
- # πŸ›’ Qwen2-VL Amazon Listing Generator (LoRA)
141
-
142
- Upload a product image and generate an Amazon-style listing with title, bullet points, description, keywords, and category.
143
-
144
- **Model**: [soupstick/qwen2vl-amazon-ft-lora](https://huggingface.co/soupstick/qwen2vl-amazon-ft-lora) (Qwen2-VL-7B + LoRA)
145
- """)
146
-
147
- with gr.Row():
148
- with gr.Column():
149
- image_input = gr.Image(
150
- type="pil",
151
- label="πŸ“Έ Upload Product Image",
152
- height=300
153
- )
154
- prompt_input = gr.Textbox(
155
- label="πŸ“ Instruction (Optional)",
156
- value="Generate Amazon listing.",
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
- --extra-index-url https://download.pytorch.org/whl/cpu
2
- gradio>=4.44.1
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