jonathanjordan21 commited on
Commit
11118c6
·
verified ·
1 Parent(s): 51c6a43

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +55 -0
app.py ADDED
@@ -0,0 +1,55 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import torch
3
+ import numpy as np
4
+
5
+ # ======== Example Dummy Model ========
6
+ # Replace this with your own model loading
7
+ class DummyModel(torch.nn.Module):
8
+ def __init__(self):
9
+ super().__init__()
10
+ self.linear = torch.nn.Linear(2, 3) # 2 inputs (lat, lon) → 3 outputs
11
+
12
+ def forward(self, x):
13
+ return self.linear(x)
14
+
15
+ # load your trained model (replace with torch.load if you have .pt file)
16
+ model = DummyModel()
17
+ model.eval()
18
+
19
+ # ======== Prediction Function ========
20
+ def predict_score(lat, lon):
21
+ # Convert input to tensor
22
+ inputs = torch.tensor([[lat, lon]], dtype=torch.float32)
23
+
24
+ # Get model output
25
+ with torch.no_grad():
26
+ outputs = model(inputs).numpy().flatten()
27
+
28
+ # Unpack into respective values
29
+ score, num_banks, normal_score = outputs
30
+
31
+ # You can apply any post-processing here
32
+ return {
33
+ "Score": round(float(score), 3),
34
+ "Num Banks": round(float(num_banks), 3),
35
+ "Normal Score": round(float(normal_score), 3),
36
+ }
37
+
38
+ # ======== Gradio Interface ========
39
+ interface = gr.Interface(
40
+ fn=predict_score,
41
+ inputs=[
42
+ gr.Number(label="Latitude"),
43
+ gr.Number(label="Longitude"),
44
+ ],
45
+ outputs=[
46
+ gr.Number(label="Score"),
47
+ gr.Number(label="Num Banks"),
48
+ gr.Number(label="Normal Score"),
49
+ ],
50
+ title="Bank Location Scoring Model",
51
+ description="Enter latitude and longitude to get the predicted score, number of banks, and normalized score.",
52
+ )
53
+
54
+
55
+ interface.launch()