SivaMallikarjun commited on
Commit
a667566
·
verified ·
1 Parent(s): 4ee3532

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +69 -0
app.py ADDED
@@ -0,0 +1,69 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import torch
3
+ from transformers import pipeline
4
+ import folium
5
+ from geopy.geocoders import Nominatim
6
+ from twilio.rest import Client
7
+ import random
8
+
9
+ # Load AI Model (Example: Hugging Face Pre-trained Model)
10
+ model = pipeline("text-classification", model="distilbert-base-uncased")
11
+
12
+ # Dummy Function for AI Hurricane Prediction
13
+ def predict_hurricane(air_pressure, wind_speed, humidity):
14
+ risk = (wind_speed * 0.5 + humidity * 0.3 + air_pressure * 0.2) / 100
15
+ prediction = "High Risk" if risk > 0.6 else "Low Risk"
16
+
17
+ return f"Hurricane Risk: {prediction} ({round(risk * 100, 2)}%)"
18
+
19
+ # Function for GIS Alert System
20
+ def send_alert(location):
21
+ # Twilio setup (Replace with your credentials)
22
+ account_sid = "your_account_sid"
23
+ auth_token = "your_auth_token"
24
+ client = Client(account_sid, auth_token)
25
+
26
+ message = client.messages.create(
27
+ body=f"⚠️ Hurricane Alert in {location}! Take necessary precautions.",
28
+ from_="+1234567890", to="+9876543210"
29
+ )
30
+ return f"Alert sent to {location}!"
31
+
32
+ # Map Generator (Visualizing Affected Areas)
33
+ def generate_map(location):
34
+ geolocator = Nominatim(user_agent="geoapi")
35
+ loc = geolocator.geocode(location)
36
+
37
+ map_ = folium.Map(location=[loc.latitude, loc.longitude], zoom_start=6)
38
+ folium.Marker([loc.latitude, loc.longitude], tooltip="Hurricane Alert 🚨").add_to(map_)
39
+
40
+ return map_._repr_html_()
41
+
42
+ # Gradio UI
43
+ with gr.Blocks() as app:
44
+ gr.Markdown("# 🌪 AI Hurricane Prediction & Alert System")
45
+
46
+ with gr.Row():
47
+ air_pressure = gr.Number(label="Air Pressure (hPa)")
48
+ wind_speed = gr.Number(label="Wind Speed (km/h)")
49
+ humidity = gr.Number(label="Humidity (%)")
50
+
51
+ predict_btn = gr.Button("Predict Hurricane Risk")
52
+ result = gr.Textbox(label="Prediction Result")
53
+
54
+ predict_btn.click(predict_hurricane, inputs=[air_pressure, wind_speed, humidity], outputs=result)
55
+
56
+ gr.Markdown("### 📍 GIS Alert System")
57
+ location = gr.Textbox(label="Enter Location")
58
+ alert_btn = gr.Button("Send Alert")
59
+ alert_result = gr.Textbox(label="Alert Status")
60
+
61
+ alert_btn.click(send_alert, inputs=location, outputs=alert_result)
62
+
63
+ gr.Markdown("### 🗺️ Map of Affected Area")
64
+ map_btn = gr.Button("Generate Map")
65
+ map_output = gr.HTML()
66
+
67
+ map_btn.click(generate_map, inputs=location, outputs=map_output)
68
+
69
+ app.launch()