Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,64 +1,61 @@
|
|
1 |
import gradio as gr
|
2 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
3 |
|
4 |
-
"""
|
5 |
-
For more information on `huggingface_hub` Inference API support, please check the docs: https://huggingface.co/docs/huggingface_hub/v0.22.2/en/guides/inference
|
6 |
-
"""
|
7 |
-
client = InferenceClient("HuggingFaceH4/zephyr-7b-beta")
|
8 |
-
|
9 |
-
|
10 |
-
def respond(
|
11 |
-
message,
|
12 |
-
history: list[tuple[str, str]],
|
13 |
-
system_message,
|
14 |
-
max_tokens,
|
15 |
-
temperature,
|
16 |
-
top_p,
|
17 |
-
):
|
18 |
-
messages = [{"role": "system", "content": system_message}]
|
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 |
+
import random
|
3 |
+
|
4 |
+
# Ahantu na coordinates
|
5 |
+
locations = {
|
6 |
+
"Downtown": {"lat": -1.95, "lon": 30.05, "avg_speed": 30, "avg_vehicles": 60},
|
7 |
+
"Highway": {"lat": -1.92, "lon": 30.06, "avg_speed": 100, "avg_vehicles": 40},
|
8 |
+
"Industrial Area": {"lat": -1.94, "lon": 30.07, "avg_speed": 50, "avg_vehicles": 30},
|
9 |
+
"School Zone": {"lat": -1.93, "lon": 30.03, "avg_speed": 20, "avg_vehicles": 20}
|
10 |
+
}
|
11 |
+
|
12 |
+
def simulate_traffic_map(area):
|
13 |
+
info = locations[area]
|
14 |
+
speed = round(random.gauss(info["avg_speed"], 10), 1)
|
15 |
+
vehicle_count = int(random.gauss(info["avg_vehicles"], 10))
|
16 |
+
if speed < 20 and vehicle_count > 50:
|
17 |
+
traffic_level = "π¦ High Traffic Jam"
|
18 |
+
status = "Blocked"
|
19 |
+
elif speed < 40 or vehicle_count > 40:
|
20 |
+
traffic_level = "β οΈ Moderate Traffic"
|
21 |
+
status = "Restricted"
|
22 |
+
else:
|
23 |
+
traffic_level = "β
Light Traffic"
|
24 |
+
status = "Clear"
|
25 |
+
|
26 |
+
report = (f"π **{area}**\n"
|
27 |
+
f"π Speed: {speed} km/h\n"
|
28 |
+
f"π Vehicles: {vehicle_count}\n"
|
29 |
+
f"π Status: {status}\n"
|
30 |
+
f"π£ Traffic: {traffic_level}")
|
31 |
+
|
32 |
+
lat, lon = info["lat"], info["lon"]
|
33 |
+
html = f"""
|
34 |
+
<div id="map" style="width:100%;height:400px;"></div>
|
35 |
+
<link rel="stylesheet" href="https://unpkg.com/leaflet/dist/leaflet.css"/>
|
36 |
+
<script src="https://unpkg.com/leaflet/dist/leaflet.js"></script>
|
37 |
+
<script>
|
38 |
+
var map = L.map('map').setView([{lat}, {lon}], 14);
|
39 |
+
L.tileLayer('https://{{s}}.tile.openstreetmap.org/{{z}}/{{x}}/{{y}}.png', {{
|
40 |
+
maxZoom: 19
|
41 |
+
}}).addTo(map);
|
42 |
+
L.marker([{lat}, {lon}])
|
43 |
+
.addTo(map)
|
44 |
+
.bindPopup("{area}: {traffic_level}")
|
45 |
+
.openPopup();
|
46 |
+
</script>
|
47 |
+
"""
|
48 |
+
return report, html
|
49 |
+
|
50 |
+
with gr.Blocks() as demo:
|
51 |
+
gr.Markdown("## πΊοΈ Traffic Monitoring with Real Map View")
|
52 |
+
|
53 |
+
location = gr.Dropdown(list(locations.keys()), label="Choose Location", value="Downtown")
|
54 |
+
simulate_btn = gr.Button("Simulate Traffic")
|
55 |
+
output = gr.Markdown()
|
56 |
+
map_view = gr.HTML()
|
57 |
+
|
58 |
+
simulate_btn.click(fn=simulate_traffic_map, inputs=location, outputs=[output, map_view])
|
59 |
+
|
60 |
+
demo.launch()
|
61 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|