gaia / app.py
AliceTt's picture
added localisation and culture choices in front
e05937f
raw
history blame
4.7 kB
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 *
with gr.Blocks() as demo:
gr.HTML(
"""
<style>
/* Custom style for a specific row */
.box {
background-color: #90909b;
# padding: 20px;
border-radius: 10px;
# border: solid 2px #4CAF50;
display: flex;
align-content: center;
padding: 20px;
}
.culture_box {
background-color: #52525b;
border-radius: 10px;
display: flex;
align-content: center;
}
</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")
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])
simulation_btn.click(
launch_simulation, [lat, lon, address, culture], [lat, lon, address, map]
)
demo.title = "Démo GAIA - Les bénéfices de l'ombrage"
# demo.description = "Example of simple chatbot with Gradio and Mistral AI via its API"
demo.launch()