Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,70 +1,83 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
|
| 3 |
-
#
|
| 4 |
stock = {
|
| 5 |
-
"
|
| 6 |
-
"
|
| 7 |
-
"
|
| 8 |
"Ibicuruzwa_A": 50,
|
| 9 |
"Ibicuruzwa_B": 8,
|
| 10 |
"Ibicuruzwa_C": 0,
|
| 11 |
"Ibicuruzwa_D": 15,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 12 |
}
|
| 13 |
|
| 14 |
-
|
| 15 |
-
""
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
""
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
messages.append(f"Umurongo '{line}' ntusobanutse neza. Format: izina, quantity")
|
| 30 |
-
continue
|
| 31 |
-
product_name = parts[0].strip()
|
| 32 |
-
try:
|
| 33 |
-
quantity = int(parts[1].strip())
|
| 34 |
-
if quantity < 0:
|
| 35 |
-
messages.append(f"Ingano y'ububiko igomba kuba itari hasi ya zeru: '{line}'")
|
| 36 |
-
continue
|
| 37 |
-
except ValueError:
|
| 38 |
-
messages.append(f"Ingano y'ububiko si integer: '{line}'")
|
| 39 |
-
continue
|
| 40 |
-
|
| 41 |
-
stock[product_name] = stock.get(product_name, 0) + quantity
|
| 42 |
-
messages.append(f"'{product_name}' yongewemo/ yavuguruwe: {stock[product_name]}")
|
| 43 |
-
|
| 44 |
-
return "\n".join(messages), gr.Dropdown.update(choices=list(stock.keys()))
|
| 45 |
|
| 46 |
-
def
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 50 |
|
| 51 |
with gr.Blocks() as demo:
|
| 52 |
-
gr.Markdown("#
|
| 53 |
|
| 54 |
-
with gr.
|
| 55 |
-
gr.
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
output_add = gr.Textbox(label="Ibisubizo byo kongera ububiko")
|
| 59 |
|
| 60 |
-
|
| 61 |
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
|
| 65 |
-
|
|
|
|
| 66 |
|
| 67 |
-
|
| 68 |
|
| 69 |
if __name__ == "__main__":
|
| 70 |
demo.launch()
|
|
|
|
|
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
|
| 3 |
+
# Stock n'ibiciro (price ku kintu kimwe)
|
| 4 |
stock = {
|
| 5 |
+
"Ibiryayi": 100,
|
| 6 |
+
"Ibitunguru": 50,
|
| 7 |
+
"Karoti": 30,
|
| 8 |
"Ibicuruzwa_A": 50,
|
| 9 |
"Ibicuruzwa_B": 8,
|
| 10 |
"Ibicuruzwa_C": 0,
|
| 11 |
"Ibicuruzwa_D": 15,
|
| 12 |
+
"Amashu": 40,
|
| 13 |
+
"Imyembe": 25,
|
| 14 |
+
"Inanasi": 60,
|
| 15 |
+
"Amashaza": 70,
|
| 16 |
+
"Ibinyomoro": 10,
|
| 17 |
+
# ... wakomeza ugashyiramo ibindi ukoresha stock yawe ...
|
| 18 |
}
|
| 19 |
|
| 20 |
+
prices = {
|
| 21 |
+
"Ibiryayi": 200, # price mu mafaranga y'u Rwanda (RWF)
|
| 22 |
+
"Ibitunguru": 150,
|
| 23 |
+
"Karoti": 120,
|
| 24 |
+
"Ibicuruzwa_A": 500,
|
| 25 |
+
"Ibicuruzwa_B": 800,
|
| 26 |
+
"Ibicuruzwa_C": 1000,
|
| 27 |
+
"Ibicuruzwa_D": 400,
|
| 28 |
+
"Amashu": 250,
|
| 29 |
+
"Imyembe": 300,
|
| 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 |
+
product_name = product_name.strip()
|
| 38 |
+
if product_name == "":
|
| 39 |
+
return "Hitamo igicuruzwa."
|
| 40 |
+
if product_name not in stock or product_name not in prices:
|
| 41 |
+
return f"Icyo gicuruzwa '{product_name}' ntikirimo mu bubiko cyangwa nta giciro gifite."
|
| 42 |
+
price = prices[product_name]
|
| 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 |
+
product_name = product_name.strip()
|
| 48 |
+
if product_name == "":
|
| 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 < 0:
|
| 53 |
+
return "Ingano y'ububiko igomba kuba itari hasi ya zeru."
|
| 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/ kongera quantity {quantity}. "
|
| 60 |
+
f"Igiciro cyose: {total_price} RWF.")
|
| 61 |
|
| 62 |
with gr.Blocks() as demo:
|
| 63 |
+
gr.Markdown("# Gucunga Ububiko & Kwerekana Ibiciro")
|
| 64 |
|
| 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 |
+
product_input = gr.Textbox(label="Andika cyangwa hitamo igicuruzwa", value="")
|
| 74 |
+
quantity_input = gr.Number(label="Andika ingano yifuza", value=0, precision=0)
|
| 75 |
+
calc_btn = gr.Button("Bara igiciro rusange")
|
| 76 |
+
total_output = gr.Textbox(label="Ibisubizo")
|
| 77 |
|
| 78 |
+
calc_btn.click(calc_total, inputs=[product_input, quantity_input], outputs=total_output)
|
| 79 |
|
| 80 |
if __name__ == "__main__":
|
| 81 |
demo.launch()
|
| 82 |
+
|
| 83 |
+
|