File size: 8,551 Bytes
7af6bd2
e05937f
 
01bf518
325a821
01bf518
8fa2802
7af6bd2
 
e05937f
121f2f7
e05937f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
38af3d3
e05937f
38af3d3
 
e05937f
38af3d3
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
e05937f
38af3d3
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
a972258
e05937f
 
 
38af3d3
 
 
 
 
 
 
 
 
 
 
e05937f
38af3d3
 
 
 
 
 
 
 
 
e05937f
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
import gradio as gr

# from mistralai import Mistral, UserMessage
from chatbot_gaia.src.main_flow import kickoff
import pandas as pd


import os

title = "Démo GAIA - Les bénéfices de l'ombrage"
description = "Example of simple chatbot with Gradio and Mistral AI via its API"
# placeholder = "Posez moi une question sur l'agriculture"
# examples = ["Je suis un agriculture basé pas loin de bordeaux et je cultive du mais et je cherche des recommandations d'autres cultures mieux adapté aux changements climatique ?",
#             "Je suis un agriculteur basé au sud de la France vers Nice, je cherche des recommandations de cultures mieux adapté aux changements climatiques ?",]

# #api_key = os.environ.get("MISTRAL_API_KEY")
# #client = MistralClient(api_key=api_key)
# #client = Mistral(api_key=api_key)
# #model = 'open-mixtral-8x7b'
# """
# def chat_with_mistral(user_input, history):
#     messages = [{"role": "user", "content": user_input}]

#     chat_response = client.chat.complete(model=model, messages=messages)P
#     return chat_response.choices[0].message.content
# """

# def chat_with_agrienergy(user_input, history):
#     messages = [{"role": "user", "content": user_input}]
#     result = kickoff(user_input=user_input)
#     return f"{result}"

# iface = gr.ChatInterface(
#     fn=chat_with_agrienergy,
#     chatbot=gr.Chatbot(height=300),
#     textbox=gr.Textbox(placeholder=placeholder, container=False, scale=7),
#     title=title,
#     description=description,
#     theme="soft",
#     examples=examples,
#     cache_examples=False,
# )

# iface.launch(share=True)


# import gradio as gr
from func_utils import *
from summary_test import generate_irradiance_trend, get_mocked_summary

def go_to_page_1():
    return gr.Column(visible=True), gr.Column(visible=False)

with gr.Blocks() as demo:
    with gr.Row():
        page_1 = gr.Column(visible=True)
        with page_1:
            gr.HTML(
                """
                <style>
                    /* Custom style for a specific row */
                    .box {
                        background-color: #90909b;
                        border-radius: 10px;
                        display: flex;
                        align-content: center;
                        padding: 20px;
                    }
                    .culture_box {
                        background-color: #52525b;
                        border-radius: 10px;
                        display: flex;
                        align-content: center;
                    }
                    .title-box{
                        background-color: #90909b;
                    }
                </style>
                """
            )
            demo.title = "Démo GAIA - Les bénéfices de l'ombrage"
            gr.HTML("<h1 style='text-align: center;'>Les bénéfices de l'ombrage</h1>")
            gr.HTML(
                "<p style='border: solid white 1px; border-radius: 10px; padding:20px'>L'outil vous permet de voir les avantages potentiels de l'ombrage sur votre exploitation. </p>"
            )

            with gr.Blocks() as infos:

                infos.title = "Informations sur votre exploitation"
                gr.HTML("<h2>Renseignez les informations relatives à votre projet</h2>")
                with gr.Row(equal_height=True):
                    with gr.Column(variant="panel", scale=1):
                        with gr.Row(equal_height=True, elem_classes="box"):
                            with gr.Tab(label="Adresse", scale=1):
                                address = gr.Textbox(
                                    label="Addresse",
                                    info="Adresse de votre projet",
                                )
                            with gr.Tab(label="Coordonnées GPS", scale=1):
                                lat = gr.Number(
                                    label="Latitude",
                                    info="Latitude de votre projet",
                                )
                                lon = gr.Number(
                                    label="Longitude",
                                    info="Longitude de votre projet",
                                )
                            place_btn = gr.Button(
                                value="Valider la localisation", size="sm"
                            )
                            place_cancel_btn = gr.Button(
                                value="Réinitialiser la localisation", size="sm"
                            )

                        with gr.Row(elem_classes="box"):
                            culture = gr.Textbox(
                                label="Culture", scale=1, elem_classes="culture_box"
                            )

                    with gr.Column(variant="panel", scale=3):
                        map = gr.HTML()

                simulation_btn = gr.Button(value="Lancer la simulation", size="lg")

            go_to_page_2_btn = gr.Button("Aller aux résultats", visible=False)

        page_2 = gr.Column(visible=False)
        with page_2:
            with gr.Blocks() as results:
                results.title = "Résultats"
                gr.HTML("<h2 style='padding: 20px'>Résultats de la simulation</h2>")
                with gr.Row(equal_height=True, elem_classes="box"):
                    with gr.Tab(label="Analyse générale", scale=1):
                        with gr.Row(elem_classes="box"):
                            with gr.Column():
                                gr.HTML("<h2>Synthèse</h2>")
                                current_situation_summary = gr.TextArea(
                                    placeholder="Synthèse de la simulation", label="", show_label=None
                                )
                        with gr.Row(elem_classes="box"):
                            with gr.Column():
                                gr.HTML("<h2>Déficit hydrique</h2>")
                                gr.Plot()
                            with gr.Column():
                                gr.HTML("<h2>Rendements</h2>")
                                gr.Plot()
                        with gr.Column(elem_classes="box"):
                            with gr.Row():
                                gr.HTML("<h2>Bilan climatique</h2>")
                            with gr.Row():
                                with gr.Column():
                                    gr.HTML("<h3>Précipitations</h2>")
                                    gr.Plot()
                                with gr.Column():
                                    gr.HTML("<h3>Evapotranspiration</h2>")
                                    gr.Plot()
                                with gr.Column():
                                    gr.HTML("<h3>Irradiance</h2>")
                                    gr.Plot()
                    with gr.Tab(label="Analyse avec AgriPv", scale=1):
                        with gr.Row(elem_classes="box"):
                            with gr.Column():
                                gr.HTML("<h2>Synthèse</h2>")
                                agripv_summary = gr.TextArea(
                                    placeholder="Synthèse de la simulation", label="", show_label=None
                                )
                        with gr.Row(elem_classes="box"):
                            with gr.Column():
                                gr.HTML("<h2>Déficit hydrique</h2>")
                                gr.Plot()
                            with gr.Column():
                                gr.HTML("<h2>Rendements</h2>")
                                gr.Plot()
                go_to_page_1_btn = gr.Button(value="Revenir aux informations du projet", size="lg")

    demo.load(on_init, [lat, lon, address], [lat, lon, map])
    place_btn.click(on_init, [lat, lon, address], [lat, lon, map])
    place_cancel_btn.click(on_delete, [lat, lon, map], [lat, lon, address, map])
    go_to_page_2_btn.click(
        fn=go_to_page_2,
        inputs="",
        outputs=[page_1, page_2],
    )
    go_to_page_1_btn.click(
        fn=go_to_page_1,
        inputs="",
        outputs=[page_1, page_2],
    )

    simulation_btn.click(
        launch_simulation,
        [lat, lon, address, culture],
        [
            current_situation_summary,
            agripv_summary,
            page_1,
            page_2,
            go_to_page_2_btn
        ],
    )
demo.title = "Démo GAIA - Les bénéfices de l'ombrage"
demo.launch()