Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -137,37 +137,36 @@ def extract_price(price_str: str) -> float:
|
|
| 137 |
match = re.search(r"\d+[.,]?\d*", price_str or "")
|
| 138 |
return float(match.group().replace(",", ".")) if match else 0.0
|
| 139 |
|
| 140 |
-
|
| 141 |
css_hide_footer = """
|
| 142 |
<style>
|
| 143 |
footer, .svelte-1ipelgc { display: none !important; }
|
| 144 |
</style>
|
| 145 |
"""
|
| 146 |
|
| 147 |
-
|
| 148 |
-
|
| 149 |
-
|
| 150 |
-
|
| 151 |
-
|
| 152 |
-
|
| 153 |
-
|
| 154 |
-
|
| 155 |
-
.
|
| 156 |
-
|
| 157 |
-
|
| 158 |
-
|
| 159 |
-
}
|
| 160 |
-
|
| 161 |
-
|
| 162 |
-
}
|
| 163 |
-
</
|
| 164 |
-
|
| 165 |
-
|
| 166 |
-
|
| 167 |
-
|
| 168 |
-
|
| 169 |
-
|
| 170 |
-
|
| 171 |
|
| 172 |
with gr.Blocks() as demo:
|
| 173 |
gr.Markdown("# 🍜🥢 EAT EAT Cafe & Bistro")
|
|
@@ -175,30 +174,18 @@ with gr.Blocks() as demo:
|
|
| 175 |
gr.Markdown(
|
| 176 |
"Your task: One starter containing mushroom,One main course containing beef;One drink that is the cheapest on the menu."
|
| 177 |
)
|
| 178 |
-
|
| 179 |
-
|
| 180 |
-
cart_state = gr.State({})
|
| 181 |
-
button_refs = []
|
| 182 |
-
with gr.Tabs():
|
| 183 |
-
for section, items in menu.items():
|
| 184 |
-
with gr.TabItem(section):
|
| 185 |
-
for item in items:
|
| 186 |
-
with gr.Row():
|
| 187 |
-
with gr.Column(scale=1):
|
| 188 |
-
gr.HTML(
|
| 189 |
-
f"<img src='{item.get('image', '')}' alt='{item.get('name', '')}' "
|
| 190 |
-
"style='height:90px;width:120px;border-radius:8px;'/>"
|
| 191 |
-
)
|
| 192 |
-
with gr.Column(scale=4):
|
| 193 |
-
name = item.get("name", "")
|
| 194 |
-
desc = item.get("description", "")
|
| 195 |
-
price_str = item.get("price", "")
|
| 196 |
-
price_html = f"<span style='font-size:1.1em;font-weight:bold;color:green;'>{price_str}</span>"
|
| 197 |
-
gr.Markdown(
|
| 198 |
-
f"**{name}**\n\n{desc}\n\n{price_html}",
|
| 199 |
-
show_label=False,
|
| 200 |
-
)
|
| 201 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 202 |
|
| 203 |
if __name__ == "__main__":
|
| 204 |
demo.launch()
|
|
|
|
| 137 |
match = re.search(r"\d+[.,]?\d*", price_str or "")
|
| 138 |
return float(match.group().replace(",", ".")) if match else 0.0
|
| 139 |
|
| 140 |
+
# 自定义样式:隐藏底部栏
|
| 141 |
css_hide_footer = """
|
| 142 |
<style>
|
| 143 |
footer, .svelte-1ipelgc { display: none !important; }
|
| 144 |
</style>
|
| 145 |
"""
|
| 146 |
|
| 147 |
+
def render_section(category):
|
| 148 |
+
"""根据所选菜单分类渲染菜品列表"""
|
| 149 |
+
section_html = ""
|
| 150 |
+
for item in menu.get(category, []):
|
| 151 |
+
image_html = f"<img src='{item.get('image', '')}' alt='{item.get('name', '')}' style='height:90px;width:120px;border-radius:8px;'/>"
|
| 152 |
+
name = item.get("name", "")
|
| 153 |
+
desc = item.get("description", "")
|
| 154 |
+
price = item.get("price", "")
|
| 155 |
+
price_html = f"<span style='font-size:1.1em;font-weight:bold;color:green;'>{price}</span>"
|
| 156 |
+
block = f"""
|
| 157 |
+
<div style='margin-bottom: 20px;'>
|
| 158 |
+
<div style='display: flex; gap: 12px;'>
|
| 159 |
+
<div>{image_html}</div>
|
| 160 |
+
<div>
|
| 161 |
+
<div><strong>{name}</strong></div>
|
| 162 |
+
<div>{desc}</div>
|
| 163 |
+
<div>{price_html}</div>
|
| 164 |
+
</div>
|
| 165 |
+
</div>
|
| 166 |
+
</div>
|
| 167 |
+
"""
|
| 168 |
+
section_html += block
|
| 169 |
+
return section_html
|
|
|
|
| 170 |
|
| 171 |
with gr.Blocks() as demo:
|
| 172 |
gr.Markdown("# 🍜🥢 EAT EAT Cafe & Bistro")
|
|
|
|
| 174 |
gr.Markdown(
|
| 175 |
"Your task: One starter containing mushroom,One main course containing beef;One drink that is the cheapest on the menu."
|
| 176 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 177 |
|
| 178 |
+
selected_category = gr.State("Starters")
|
| 179 |
+
menu_display = gr.HTML(render_section("Starters"))
|
| 180 |
+
|
| 181 |
+
with gr.Row():
|
| 182 |
+
for cat in menu.keys():
|
| 183 |
+
gr.Button(cat).click(
|
| 184 |
+
lambda c=cat: (c, render_section(c)),
|
| 185 |
+
outputs=[selected_category, menu_display],
|
| 186 |
+
)
|
| 187 |
+
|
| 188 |
+
menu_display.render()
|
| 189 |
|
| 190 |
if __name__ == "__main__":
|
| 191 |
demo.launch()
|