RSHVR commited on
Commit
38cec02
·
verified ·
1 Parent(s): 15b25d4

Delete frontend.py

Browse files
Files changed (1) hide show
  1. frontend.py +0 -91
frontend.py DELETED
@@ -1,91 +0,0 @@
1
- import gradio as gr
2
- import requests
3
-
4
- API_URL = "http://localhost:8000/extract"
5
-
6
- def get_product_data_from_url(url):
7
- """
8
- Retrieve product data (images, measurements, materials) from the API.
9
-
10
- Args:
11
- url: Product URL to extract data from
12
-
13
- Returns:
14
- Tuple of (image_list, measurements_str, materials_str)
15
- """
16
- try:
17
- payload = {
18
- "url": url,
19
- "download_images": False
20
- }
21
-
22
- response = requests.post(API_URL, json=payload)
23
- response.raise_for_status()
24
- data = response.json()
25
-
26
- # Extract images
27
- images = [img["url"] for img in data.get("images", {}).values()]
28
-
29
- # Format measurements into markdown
30
- measurements = data.get("measurements", {})
31
- if measurements:
32
- measurements_str = "\n".join([f"- **{k.title()}**: {v}" for k, v in measurements.items()])
33
- else:
34
- measurements_str = "No measurements found."
35
-
36
- # Format materials into markdown
37
- materials = data.get("materials", {})
38
- if materials:
39
- materials_str = "\n".join([f"- **{k.title()}**: {v}" for k, v in materials.items()])
40
- else:
41
- materials_str = "No materials information found."
42
-
43
- return images, measurements_str, materials_str
44
-
45
- except Exception as e:
46
- error_message = f"Error: {str(e)}"
47
- return [], error_message, error_message
48
-
49
- def create_interface():
50
- """Create and configure the Gradio interface"""
51
- with gr.Blocks(title="IKEA Product Image + Measurement Extractor") as demo:
52
- gr.Markdown("## IKEA Product Image + Measurement Extractor")
53
- gr.Markdown("Enter an IKEA product URL to extract images, measurements, and materials information.")
54
-
55
- with gr.Row():
56
- with gr.Column(scale=1):
57
- # Input section
58
- url_input = gr.Textbox(
59
- label="Product URL",
60
- placeholder="https://www.ikea.com/product/...",
61
- info="Paste IKEA product URL here"
62
- )
63
- submit_btn = gr.Button("Extract Product Data", variant="primary")
64
-
65
- # Results section - Measurements and Materials
66
- with gr.Accordion("Product Information", open=True):
67
- measurements_display = gr.Markdown(label="Measurements")
68
- materials_display = gr.Markdown(label="Materials")
69
-
70
- with gr.Column(scale=2):
71
- # Gallery component for displaying images
72
- image_gallery = gr.Gallery(
73
- label="Product Images",
74
- show_label=True,
75
- columns=2,
76
- height=500,
77
- object_fit="contain"
78
- )
79
-
80
- # Set up the click event
81
- submit_btn.click(
82
- fn=get_product_data_from_url,
83
- inputs=url_input,
84
- outputs=[image_gallery, measurements_display, materials_display]
85
- )
86
-
87
- return demo
88
-
89
- if __name__ == "__main__":
90
- demo = create_interface()
91
- demo.launch(share=False)