Spaces:
Sleeping
Sleeping
| import gradio as gr | |
| import TWS_fonctions | |
| import os | |
| # Load external CSS | |
| with open("gradio.css", "r") as f: | |
| thecss = f.read() | |
| # --- Common Interface Options --- | |
| INTERFACE_KWARGS = { | |
| "flagging_mode": "never", | |
| # css moved to launch() | |
| } | |
| # --- Inventory Management Views --- | |
| def create_cellar_tab(): | |
| with gr.Column(): | |
| add_to_cellar = gr.Interface( | |
| fn=TWS_fonctions.add_to_cellar, | |
| inputs=gr.Textbox(placeholder="Add 12 bottles of Margaux 2015", label="Wine Details"), | |
| outputs=[gr.Textbox(label="Status")], | |
| title="Add Wine", | |
| description="Manage your collection with zero friction.", | |
| **INTERFACE_KWARGS | |
| ) | |
| remove_from_cellar = gr.Interface( | |
| fn=TWS_fonctions.remove_from_cellar, | |
| inputs=gr.Textbox(placeholder="Remove 2 bottles of Chablis", label="Wine Details"), | |
| outputs=[gr.Textbox(label="Status")], | |
| title="Remove Wine", | |
| description="Keep your inventory precisely up to date.", | |
| **INTERFACE_KWARGS | |
| ) | |
| cellar_inventory = gr.Interface( | |
| fn=TWS_fonctions.cellar_inventory, | |
| inputs=gr.Textbox(placeholder="List all bottles", label="Search"), | |
| outputs=[gr.Textbox(label="Inventory")], | |
| title="Inventory", | |
| description="A comprehensive view of your digital cellar.", | |
| **INTERFACE_KWARGS | |
| ) | |
| cellar_reset = gr.Interface( | |
| fn=TWS_fonctions.cellar_reset, | |
| inputs=[], | |
| outputs=[gr.Textbox(label="Status")], | |
| title="Reset", | |
| description="⚠️ Permanent removal of all records.", | |
| **INTERFACE_KWARGS | |
| ) | |
| return True | |
| ##return [add_to_cellar, remove_from_cellar, cellar_inventory, cellar_reset] | |
| def create_research_tab(): | |
| with gr.Column(): | |
| info_bottle = gr.Interface( | |
| fn=TWS_fonctions.info_bottle, | |
| inputs=gr.Image(type="pil", label="Label Photo"), | |
| outputs=[gr.Textbox(label="Result")], | |
| title="Recognize", | |
| description="Identify any bottle with architectural precision.", | |
| **INTERFACE_KWARGS | |
| ) | |
| find_data_bottle = gr.Interface( | |
| fn=TWS_fonctions.find_data_bottle, | |
| inputs=[gr.Textbox(placeholder="Talbot 2018", label="Wine Name")], | |
| outputs=[gr.Textbox(label="Intelligence")], | |
| title="Web Search", | |
| description="Professional data and technical specifications.", | |
| **INTERFACE_KWARGS | |
| ) | |
| find_data_bottle_image = gr.Interface( | |
| fn=TWS_fonctions.find_data_bottle_image, | |
| inputs=[gr.Image(type="pil", label="Label Photo")], | |
| outputs=[gr.Textbox(label="Intelligence")], | |
| title="Image Intelligence", | |
| description="Identify and deep-dive in one motion.", | |
| **INTERFACE_KWARGS | |
| ) | |
| get_search_bottle = gr.Interface( | |
| fn=TWS_fonctions.get_search_bottle, | |
| inputs=[gr.Textbox(placeholder="Bordeaux blends", label="Search")], | |
| outputs=[gr.Textbox(label="Catalogue")], | |
| title="Digital Library", | |
| description="Navigate a 100k wine database curated by AI.", | |
| **INTERFACE_KWARGS | |
| ) | |
| return [info_bottle, find_data_bottle, find_data_bottle_image, get_search_bottle] | |
| def create_ratings_tab(): | |
| with gr.Column(): | |
| add_commment_bottle = gr.Interface( | |
| fn=TWS_fonctions.add_commment_bottle, | |
| inputs=[gr.Textbox(placeholder="Minimalist note...", label="Notes")], | |
| outputs=[gr.Textbox(label="Status")], | |
| title="New Entry", | |
| description="Record your impressions with simplicity.", | |
| **INTERFACE_KWARGS | |
| ) | |
| add_commment_bottle_image = gr.Interface( | |
| fn=TWS_fonctions.add_commment_bottle_image, | |
| inputs=[ | |
| gr.Textbox(placeholder="Tasting notes...", label="Notes"), | |
| gr.Image(type="pil", label="Visual Context") | |
| ], | |
| outputs=[gr.Textbox(label="Status")], | |
| title="Visual Memory", | |
| description="Pair your thoughts with the aesthetic of the label.", | |
| **INTERFACE_KWARGS | |
| ) | |
| get_commment_bottle = gr.Interface( | |
| fn=TWS_fonctions.get_commment_bottle, | |
| inputs=[gr.Textbox(placeholder="Search by name", label="Wine Name")], | |
| outputs=[gr.Textbox(label="Analysis")], | |
| title="Recall", | |
| description="Access your history instantly.", | |
| **INTERFACE_KWARGS | |
| ) | |
| get_commment_bottle_image = gr.Interface( | |
| fn=TWS_fonctions.get_commment_bottle_image, | |
| inputs=[gr.Image(type="pil", label="Visual Prompt")], | |
| outputs=[gr.Textbox(label="Analysis")], | |
| title="Visual Recall", | |
| description="Scan a bottle to find your previous ratings.", | |
| **INTERFACE_KWARGS | |
| ) | |
| get_best_bottle = gr.Interface( | |
| fn=TWS_fonctions.get_best_bottle, | |
| inputs=[], | |
| outputs=[gr.Textbox(label="Recommendation")], | |
| title="Prestige Selection", | |
| description="The highest rated selections from your memory.", | |
| **INTERFACE_KWARGS | |
| ) | |
| return [add_commment_bottle, add_commment_bottle_image, get_commment_bottle, get_commment_bottle_image, get_best_bottle] | |
| # --- Main Application Layout --- | |
| # --- Main Application Layout --- | |
| with gr.Blocks() as demo: | |
| with gr.Column(elem_id="main-container"): | |
| gr.Markdown( | |
| """ | |
| # The Wine Stain | |
| ## AI SOMMELIER & CELLAR MANAGEMENT | |
| """ | |
| ) | |
| with gr.Tabs(): | |
| with gr.TabItem("CELLAR"): | |
| create_cellar_tab() | |
| with gr.TabItem("INTELLIGENCE"): | |
| create_research_tab() | |
| with gr.TabItem("MEMORY"): | |
| create_ratings_tab() | |
| with gr.Row(elem_id="minimal-footer"): | |
| gr.Markdown( | |
| """ | |
| Designed with love for the wine lovers. | |
| """ | |
| ) | |
| if __name__ == "__main__": | |
| # Removed theme from Blocks as per warning, but launch doesn't typically accept theme object. | |
| # However, css warning was explicit. Theme is strictly Blocks arg usually. | |
| # Let's try passing just css to launch first as that's the main warning source from Interface. | |
| # If theme warning is real, we might need a workaround or verify if launch accepts theme. | |
| # Standard: Blocks(theme=...) is correct for 4.x/5.x. | |
| # Warning might be false positive for Blocks theme if it came from Interface constructor reuse. | |
| # But let's try moving css to launch. | |
| demo.launch(mcp_server=True, server_name="0.0.0.0", allowed_paths=["/"], css=thecss) | |