Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,64 +1,71 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
-
from huggingface_hub import InferenceClient
|
| 3 |
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
"""
|
| 7 |
-
client = InferenceClient("HuggingFaceH4/zephyr-7b-beta")
|
| 8 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 9 |
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
)
|
| 18 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 19 |
|
| 20 |
-
for val in history:
|
| 21 |
-
if val[0]:
|
| 22 |
-
messages.append({"role": "user", "content": val[0]})
|
| 23 |
-
if val[1]:
|
| 24 |
-
messages.append({"role": "assistant", "content": val[1]})
|
| 25 |
-
|
| 26 |
-
messages.append({"role": "user", "content": message})
|
| 27 |
-
|
| 28 |
-
response = ""
|
| 29 |
-
|
| 30 |
-
for message in client.chat_completion(
|
| 31 |
-
messages,
|
| 32 |
-
max_tokens=max_tokens,
|
| 33 |
-
stream=True,
|
| 34 |
-
temperature=temperature,
|
| 35 |
-
top_p=top_p,
|
| 36 |
-
):
|
| 37 |
-
token = message.choices[0].delta.content
|
| 38 |
-
|
| 39 |
-
response += token
|
| 40 |
-
yield response
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
"""
|
| 44 |
-
For information on how to customize the ChatInterface, peruse the gradio docs: https://www.gradio.app/docs/chatinterface
|
| 45 |
-
"""
|
| 46 |
-
demo = gr.ChatInterface(
|
| 47 |
-
respond,
|
| 48 |
-
additional_inputs=[
|
| 49 |
-
gr.Textbox(value="You are a friendly Chatbot.", label="System message"),
|
| 50 |
-
gr.Slider(minimum=1, maximum=2048, value=512, step=1, label="Max new tokens"),
|
| 51 |
-
gr.Slider(minimum=0.1, maximum=4.0, value=0.7, step=0.1, label="Temperature"),
|
| 52 |
-
gr.Slider(
|
| 53 |
-
minimum=0.1,
|
| 54 |
-
maximum=1.0,
|
| 55 |
-
value=0.95,
|
| 56 |
-
step=0.05,
|
| 57 |
-
label="Top-p (nucleus sampling)",
|
| 58 |
-
),
|
| 59 |
-
],
|
| 60 |
-
)
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
if __name__ == "__main__":
|
| 64 |
-
demo.launch()
|
|
|
|
| 1 |
import gradio as gr
|
|
|
|
| 2 |
|
| 3 |
+
# Ibyo dushaka kugenzura: power output (kW) n'ibikoresho bikoresha power
|
| 4 |
+
# Turi gutegura loads 3: amatara, firigo, televiziyo
|
|
|
|
|
|
|
| 5 |
|
| 6 |
+
def energy_management(power_output, light_load, fridge_load, tv_load):
|
| 7 |
+
total_load = light_load + fridge_load + tv_load
|
| 8 |
+
messages = []
|
| 9 |
+
|
| 10 |
+
messages.append(f"🔌 Power output available: {power_output} kW")
|
| 11 |
+
messages.append(f"💡 Total load demand: {total_load} kW")
|
| 12 |
+
|
| 13 |
+
if power_output >= total_load:
|
| 14 |
+
surplus = power_output - total_load
|
| 15 |
+
messages.append(f"✅ Power is sufficient. Surplus: {surplus:.2f} kW")
|
| 16 |
+
messages.append("🔋 Amashanyarazi asigaye ashobora kubikwa cyangwa gukoreshwa mu bindi bikoresho.")
|
| 17 |
+
else:
|
| 18 |
+
deficit = total_load - power_output
|
| 19 |
+
messages.append(f"⚠️ Power deficit! Kurwanya deficit: {deficit:.2f} kW")
|
| 20 |
+
# Gukata load zidakenewe
|
| 21 |
+
# Tugena priority: Firigo > TV > Lights
|
| 22 |
+
load_status = {}
|
| 23 |
+
remaining_power = power_output
|
| 24 |
+
|
| 25 |
+
# Firigo ifite priority ya mbere
|
| 26 |
+
if fridge_load <= remaining_power:
|
| 27 |
+
load_status["Fridge"] = "ON"
|
| 28 |
+
remaining_power -= fridge_load
|
| 29 |
+
else:
|
| 30 |
+
load_status["Fridge"] = "OFF"
|
| 31 |
+
|
| 32 |
+
# TV ifite priority ya kabiri
|
| 33 |
+
if tv_load <= remaining_power:
|
| 34 |
+
load_status["TV"] = "ON"
|
| 35 |
+
remaining_power -= tv_load
|
| 36 |
+
else:
|
| 37 |
+
load_status["TV"] = "OFF"
|
| 38 |
+
|
| 39 |
+
# Lights ifite priority ya nyuma
|
| 40 |
+
if light_load <= remaining_power:
|
| 41 |
+
load_status["Lights"] = "ON"
|
| 42 |
+
remaining_power -= light_load
|
| 43 |
+
else:
|
| 44 |
+
load_status["Lights"] = "OFF"
|
| 45 |
+
|
| 46 |
+
messages.append("📉 Ibyuma byakozweho:")
|
| 47 |
+
for device, status in load_status.items():
|
| 48 |
+
messages.append(f" - {device}: {status}")
|
| 49 |
+
|
| 50 |
+
return "\n".join(messages)
|
| 51 |
|
| 52 |
+
with gr.Blocks() as demo:
|
| 53 |
+
gr.Markdown("## Energy Management System Simulation")
|
| 54 |
+
|
| 55 |
+
power_output = gr.Slider(0, 10, step=0.1, label="Power Output (kW)", value=5)
|
| 56 |
+
|
| 57 |
+
light_load = gr.Slider(0, 5, step=0.1, label="Lights Load (kW)", value=1)
|
| 58 |
+
fridge_load = gr.Slider(0, 5, step=0.1, label="Fridge Load (kW)", value=2)
|
| 59 |
+
tv_load = gr.Slider(0, 5, step=0.1, label="TV Load (kW)", value=1)
|
| 60 |
+
|
| 61 |
+
output = gr.Textbox(label="System Report", lines=12)
|
| 62 |
+
|
| 63 |
+
inputs = [power_output, light_load, fridge_load, tv_load]
|
| 64 |
+
for inp in inputs:
|
| 65 |
+
inp.change(fn=energy_management, inputs=inputs, outputs=output)
|
| 66 |
+
|
| 67 |
+
# Report ya mbere
|
| 68 |
+
output.value = energy_management(power_output.value, light_load.value, fridge_load.value, tv_load.value)
|
| 69 |
+
|
| 70 |
+
demo.launch()
|
| 71 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|