youl commited on
Commit
eb7f934
1 Parent(s): 8be5e2f

Delete app.py

Browse files
Files changed (1) hide show
  1. app.py +0 -109
app.py DELETED
@@ -1,109 +0,0 @@
1
- import gradio as gr
2
- from api import *
3
- from processing import *
4
- import pandas as pd
5
- from indices import indices
6
- import xgboost as xgb
7
- from lightgbm import LGBMRegressor
8
- import pickle
9
- import json
10
- #import boto3
11
- from shapely.geometry import MultiPolygon,shape
12
- from shapely.geometry import Point
13
- from shapely.geometry.polygon import Polygon
14
- from glob import glob
15
- import wget
16
-
17
-
18
- def predict(location_name,lat, lon):
19
- cord = [lon,lat]
20
- lon = round(lon,4)
21
- lat = round(lat,4)
22
- x1 = [lon,lat]
23
- x2 = [lat,lon]
24
- with open("data/CIV_0.json","r") as file:
25
- data = json.load(file)
26
- # extract ivory coast polygone
27
- features = [data['features'][0]['geometry']['coordinates'][0]+data['features'][0]['geometry']['coordinates'][1]+data['features'][0]['geometry']['coordinates'][2]]
28
- data['features'][0]['geometry']['coordinates'] = features
29
- ci_polygone = data['features'][0]['geometry']['coordinates'][0][0]
30
- point1 = Point(x1)
31
- point2 = Point(x2)
32
- polygon = Polygon(ci_polygone)
33
- result = polygon.contains(point1)
34
-
35
- if not result:
36
- return "Choisissez une zone de la CI","","","",""
37
-
38
- else:
39
- df = pd.read_csv("data/frame.csv")
40
- name = find_good_tile(df,point2)
41
- if name ==404:
42
- reponse = "Sentinel-2 ne dispose pas de données ce sur ce lieu à ce jour"
43
- return reponse,"","","",""
44
- else:
45
- path = "https://data354-public-assets.s3.eu-west-3.amazonaws.com/cisentineldata/"
46
- url = path+name
47
- wget.download(url)
48
- unzip()
49
- name,cld_prob,days_ago = select_best_cloud_coverage_tile()
50
- bandes_path_10,bandes_path_20,bandes_path_60,tile_path,path_cld_20,path_cld_60 =paths(name)
51
- # create image dataset
52
- images_10 = extract_sub_image(bandes_path_10,tile_path,cord)
53
-
54
- ## bandes with 20m resolution
55
- #path_cld_20
56
- images_20 = extract_sub_image(bandes_path_20,tile_path,cord,20,1)
57
-
58
- # bandes with 60m resolution
59
- #path_cld_60
60
- images_60 = extract_sub_image(bandes_path_60,tile_path,cord,60)
61
- #
62
- feature = images_10.tolist()+images_20.tolist()+images_60.tolist()
63
- bands = ['B02', 'B03', 'B04', 'B05', 'B06', 'B07', 'B08', 'B8A', 'B11', 'B12','B01','B09']
64
- X = pd.DataFrame([feature],columns = bands)
65
- # vegetation index calculation
66
- X = indices(X)
67
- # load the model from disk
68
- filename = "data/new_version_model.sav"
69
- loaded_model = pickle.load(open(filename, 'rb'))
70
- # make prediction
71
- biomass = loaded_model.predict(X)[0]
72
- carbon = 0.55*biomass
73
-
74
- # NDVI
75
- ndvi_index = ndvi(cord,name)
76
-
77
- # deleted download files
78
- delete_tiles()
79
-
80
- return str(cld_prob)+ " % cloud coverage", str(days_ago)+" days ago",str(biomass)+" Kg/ha", str(carbon)+" KgC/ha","NDVI: "+ str(ndvi_index)
81
-
82
- # Create title, description and article strings
83
- title = "🌴BEEPAS : Biomass estimation to Evaluate the Environmental Performance of Agroforestry Systems🌴"
84
- description = "This application estimates the biomass of certain areas using AI and satellite images (S2)."
85
- article = "Created by data354."
86
-
87
- # Create examples list from "examples/" directory
88
- #example_list = [["examples/" + example] for example in os.listdir("examples")]
89
- example_list = [["Foret du banco :",5.379913, -4.050445],["Pharmacie Y4 :",5.363292, -3.9481601],["Hotel ivoire :",5.316458, -4.017172],["Adjamé :",5.346938, -4.027849]]
90
-
91
- outputs = [
92
- gr.Textbox(label="Cloud coverage"),
93
- gr.Textbox(label="Number of days since sensing"),
94
- gr.Textbox(label="Above ground biomass density(AGBD) Kg/ha"),
95
- gr.Textbox(label="Carbon stock density KgC/ha "),
96
- gr.Textbox(label="Mean NDVI"),]
97
-
98
-
99
- demo = gr.Interface(
100
- fn=predict,
101
- inputs=["text","number", "number"],
102
- outputs=outputs, #[ "text", "text","text","text","text"],
103
- examples=example_list,
104
- title=title,
105
- description=description,
106
- article=article,
107
- )
108
-
109
- demo.launch(share=True)