Spaces:
				
			
			
	
			
			
		Sleeping
		
	
	
	
			
			
	
	
	
	
		
		
		Sleeping
		
	Update app.py
Browse files
    	
        app.py
    CHANGED
    
    | @@ -14,11 +14,10 @@ stock = { | |
| 14 | 
             
                "Inanasi": 60,
         | 
| 15 | 
             
                "Amashaza": 70,
         | 
| 16 | 
             
                "Ibinyomoro": 10,
         | 
| 17 | 
            -
                # ... wakomeza ugashyiramo ibindi ukoresha stock yawe ...
         | 
| 18 | 
             
            }
         | 
| 19 |  | 
| 20 | 
             
            prices = {
         | 
| 21 | 
            -
                "Ibiryayi": 200, | 
| 22 | 
             
                "Ibitunguru": 150,
         | 
| 23 | 
             
                "Karoti": 120,
         | 
| 24 | 
             
                "Ibicuruzwa_A": 500,
         | 
| @@ -30,33 +29,31 @@ prices = { | |
| 30 | 
             
                "Inanasi": 350,
         | 
| 31 | 
             
                "Amashaza": 180,
         | 
| 32 | 
             
                "Ibinyomoro": 600,
         | 
| 33 | 
            -
                # ... na hano ukoresha prices ku bicuruzwa byose ...
         | 
| 34 | 
             
            }
         | 
| 35 |  | 
| 36 | 
             
            def show_price(product_name):
         | 
| 37 | 
            -
                 | 
| 38 | 
            -
                if product_name == "":
         | 
| 39 | 
             
                    return "Hitamo igicuruzwa."
         | 
| 40 | 
            -
                 | 
|  | |
|  | |
| 41 | 
             
                    return f"Icyo gicuruzwa '{product_name}' ntikirimo mu bubiko cyangwa nta giciro gifite."
         | 
| 42 | 
            -
                 | 
| 43 | 
            -
                quantity = stock[product_name]
         | 
| 44 | 
            -
                return (f"Igicuruzwa '{product_name}' gifite ububiko bungana na {quantity} kandi igiciro cya kimwe ni {price} RWF.")
         | 
| 45 |  | 
| 46 | 
             
            def calc_total(product_name, quantity):
         | 
| 47 | 
            -
                 | 
| 48 | 
            -
             | 
| 49 | 
            -
                    return "Andika cyangwa hitamo igicuruzwa."
         | 
| 50 | 
             
                if product_name not in stock or product_name not in prices:
         | 
| 51 | 
             
                    return f"Icyo gicuruzwa '{product_name}' ntikirimo mu bubiko cyangwa nta giciro gifite."
         | 
| 52 | 
            -
                if quantity  | 
| 53 | 
            -
                    return " | 
| 54 | 
            -
                
         | 
| 55 | 
             
                available = stock[product_name]
         | 
| 56 | 
             
                price = prices[product_name]
         | 
|  | |
|  | |
| 57 | 
             
                total_price = price * quantity
         | 
| 58 | 
             
                return (f"Ububiko bwa '{product_name}' ni {available}. "
         | 
| 59 | 
            -
                        f"Uhisemo kugura | 
| 60 | 
             
                        f"Igiciro cyose: {total_price} RWF.")
         | 
| 61 |  | 
| 62 | 
             
            with gr.Blocks() as demo:
         | 
| @@ -65,17 +62,17 @@ with gr.Blocks() as demo: | |
| 65 | 
             
                with gr.Row():
         | 
| 66 | 
             
                    product_dropdown = gr.Dropdown(choices=list(stock.keys()), label="Hitamo igicuruzwa")
         | 
| 67 | 
             
                    show_price_btn = gr.Button("Erekana igiciro n'ububiko")
         | 
| 68 | 
            -
                    price_output = gr.Textbox(label="Ibisubizo")
         | 
| 69 |  | 
| 70 | 
             
                show_price_btn.click(show_price, inputs=product_dropdown, outputs=price_output)
         | 
| 71 |  | 
| 72 | 
             
                with gr.Row():
         | 
| 73 | 
            -
                     | 
| 74 | 
            -
                    quantity_input = gr.Number(label="Andika ingano yifuza", value= | 
| 75 | 
             
                    calc_btn = gr.Button("Bara igiciro rusange")
         | 
| 76 | 
            -
                    total_output = gr.Textbox(label="Ibisubizo")
         | 
| 77 |  | 
| 78 | 
            -
                calc_btn.click(calc_total, inputs=[ | 
| 79 |  | 
| 80 | 
             
            if __name__ == "__main__":
         | 
| 81 | 
             
                demo.launch()
         | 
|  | |
| 14 | 
             
                "Inanasi": 60,
         | 
| 15 | 
             
                "Amashaza": 70,
         | 
| 16 | 
             
                "Ibinyomoro": 10,
         | 
|  | |
| 17 | 
             
            }
         | 
| 18 |  | 
| 19 | 
             
            prices = {
         | 
| 20 | 
            +
                "Ibiryayi": 200,
         | 
| 21 | 
             
                "Ibitunguru": 150,
         | 
| 22 | 
             
                "Karoti": 120,
         | 
| 23 | 
             
                "Ibicuruzwa_A": 500,
         | 
|  | |
| 29 | 
             
                "Inanasi": 350,
         | 
| 30 | 
             
                "Amashaza": 180,
         | 
| 31 | 
             
                "Ibinyomoro": 600,
         | 
|  | |
| 32 | 
             
            }
         | 
| 33 |  | 
| 34 | 
             
            def show_price(product_name):
         | 
| 35 | 
            +
                if not product_name:
         | 
|  | |
| 36 | 
             
                    return "Hitamo igicuruzwa."
         | 
| 37 | 
            +
                price = prices.get(product_name)
         | 
| 38 | 
            +
                quantity = stock.get(product_name)
         | 
| 39 | 
            +
                if price is None or quantity is None:
         | 
| 40 | 
             
                    return f"Icyo gicuruzwa '{product_name}' ntikirimo mu bubiko cyangwa nta giciro gifite."
         | 
| 41 | 
            +
                return f"Igicuruzwa '{product_name}' gifite ububiko bungana na {quantity} kandi igiciro cya kimwe ni {price} RWF."
         | 
|  | |
|  | |
| 42 |  | 
| 43 | 
             
            def calc_total(product_name, quantity):
         | 
| 44 | 
            +
                if not product_name:
         | 
| 45 | 
            +
                    return "Hitamo igicuruzwa."
         | 
|  | |
| 46 | 
             
                if product_name not in stock or product_name not in prices:
         | 
| 47 | 
             
                    return f"Icyo gicuruzwa '{product_name}' ntikirimo mu bubiko cyangwa nta giciro gifite."
         | 
| 48 | 
            +
                if quantity is None or quantity <= 0:
         | 
| 49 | 
            +
                    return "Andika ingano yifuza kugura (ikwiye kuba irenze 0)."
         | 
|  | |
| 50 | 
             
                available = stock[product_name]
         | 
| 51 | 
             
                price = prices[product_name]
         | 
| 52 | 
            +
                if quantity > available:
         | 
| 53 | 
            +
                    return f"Ububiko bwa '{product_name}' buboneka ni {available}, ntabwo ushobora kugura {quantity}."
         | 
| 54 | 
             
                total_price = price * quantity
         | 
| 55 | 
             
                return (f"Ububiko bwa '{product_name}' ni {available}. "
         | 
| 56 | 
            +
                        f"Uhisemo kugura quantity {quantity}. "
         | 
| 57 | 
             
                        f"Igiciro cyose: {total_price} RWF.")
         | 
| 58 |  | 
| 59 | 
             
            with gr.Blocks() as demo:
         | 
|  | |
| 62 | 
             
                with gr.Row():
         | 
| 63 | 
             
                    product_dropdown = gr.Dropdown(choices=list(stock.keys()), label="Hitamo igicuruzwa")
         | 
| 64 | 
             
                    show_price_btn = gr.Button("Erekana igiciro n'ububiko")
         | 
| 65 | 
            +
                    price_output = gr.Textbox(label="Ibisubizo", interactive=False)
         | 
| 66 |  | 
| 67 | 
             
                show_price_btn.click(show_price, inputs=product_dropdown, outputs=price_output)
         | 
| 68 |  | 
| 69 | 
             
                with gr.Row():
         | 
| 70 | 
            +
                    product_dropdown2 = gr.Dropdown(choices=list(stock.keys()), label="Hitamo igicuruzwa (kubara igiciro rusange)")
         | 
| 71 | 
            +
                    quantity_input = gr.Number(label="Andika ingano yifuza kugura", value=1, precision=0)
         | 
| 72 | 
             
                    calc_btn = gr.Button("Bara igiciro rusange")
         | 
| 73 | 
            +
                    total_output = gr.Textbox(label="Ibisubizo", interactive=False)
         | 
| 74 |  | 
| 75 | 
            +
                calc_btn.click(calc_total, inputs=[product_dropdown2, quantity_input], outputs=total_output)
         | 
| 76 |  | 
| 77 | 
             
            if __name__ == "__main__":
         | 
| 78 | 
             
                demo.launch()
         | 
