Spaces:
Running
Running
Commit
·
18eb5f6
1
Parent(s):
022f4fb
Added feedback tab
Browse files- app.py +51 -48
- src/feedback.py +54 -0
app.py
CHANGED
@@ -20,6 +20,7 @@ from src.tools import (RefugeTool,
|
|
20 |
GetRoutesTool,
|
21 |
DescribeRouteTool,
|
22 |
RecentOutingsTool)
|
|
|
23 |
from folium import Map, TileLayer, Marker, Icon
|
24 |
from dotenv import load_dotenv
|
25 |
|
@@ -183,56 +184,57 @@ Profitez de vos aventures en ski de randonnée en France, mais vérifiez toujour
|
|
183 |
|
184 |
|
185 |
skier_agent = gr.State(lambda: init_default_agent(default_engine))
|
186 |
-
with gr.
|
187 |
-
with gr.
|
188 |
-
|
189 |
-
|
190 |
-
|
191 |
-
|
192 |
-
|
193 |
-
|
194 |
-
|
195 |
-
|
196 |
-
|
197 |
-
|
198 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
199 |
|
200 |
-
|
201 |
-
|
202 |
-
|
203 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
204 |
)
|
205 |
-
|
206 |
-
|
207 |
-
|
208 |
-
stored_message = gr.State([])
|
209 |
-
chatbot = gr.Chatbot(label="Agent Thoughts", type="messages")
|
210 |
-
warning = gr.Warning("The agent can take few seconds to minutes to respond.", visible=True)
|
211 |
-
text_output = gr.Markdown(value=FINAL_MESSAGE_HEADER, container=True)
|
212 |
-
warning = gr.Markdown("⚠️ The agent can take few seconds to minutes to respond.", container=True)
|
213 |
-
text_input = gr.Textbox(lines=1, label="Chat Message", submit_btn=True, elem_classes=["custom-textbox"])
|
214 |
-
with gr.Accordion("🇬🇧 English examples"):
|
215 |
-
gr.Examples(["Can you suggest a ski touring itinerary, near Chamonix, of moderate difficulty, with good weather and safe avalanche conditions? ",
|
216 |
-
"What are current weather and avalanche conditions in the Vanoise range?"], text_input)
|
217 |
-
with gr.Accordion("🇫🇷 Exemples en français", open=False):
|
218 |
-
gr.Examples(["Poux-tu suggérer un itinéraire de ski de randonnée, près de Chamonix, d'une difficulté modérée, avec de bonnes conditions météorologiques et un risque avalanche peu élevé?",
|
219 |
-
"Quelles sont les conditions météorologiques et le risque avalanche dans le massif de la Vanoise ?"], text_input)
|
220 |
-
|
221 |
-
with gr.Column():
|
222 |
-
f_map = Folium(value=Map(
|
223 |
-
location=[45.9237, 6.8694],
|
224 |
-
zoom_start=10,
|
225 |
-
tiles= TileLayer(
|
226 |
-
tiles=MAP_URL,
|
227 |
-
attr="Google",
|
228 |
-
name="Google Maps",
|
229 |
-
overlay=True,
|
230 |
-
control=True )
|
231 |
-
)
|
232 |
-
)
|
233 |
-
|
234 |
-
df_routes = gr.State(pd.DataFrame(df_sample_routes))
|
235 |
-
data = gr.DataFrame(value=df_routes.value[["Name", "Route Link"]], datatype="markdown", interactive=False)
|
236 |
|
237 |
language_button.click(lambda s: {"specific_agent_role_prompt": SKI_TOURING_ASSISTANT_PROMPT.format(language=s)}, [language], [skier_agent_prompt])
|
238 |
update_engine.click(
|
@@ -248,6 +250,7 @@ Profitez de vos aventures en ski de randonnée en France, mais vérifiez toujour
|
|
248 |
data.select(
|
249 |
update_map_on_selection, [data, df_routes],[f_map]
|
250 |
)
|
|
|
251 |
|
252 |
demo.launch()
|
253 |
|
|
|
20 |
GetRoutesTool,
|
21 |
DescribeRouteTool,
|
22 |
RecentOutingsTool)
|
23 |
+
from src.feedback import get_feedback_interface
|
24 |
from folium import Map, TileLayer, Marker, Icon
|
25 |
from dotenv import load_dotenv
|
26 |
|
|
|
184 |
|
185 |
|
186 |
skier_agent = gr.State(lambda: init_default_agent(default_engine))
|
187 |
+
with gr.Tab("🤖"):
|
188 |
+
with gr.Row():
|
189 |
+
with gr.Column():
|
190 |
+
language = gr.Radio(["English", "French"], value="French", label="Language")
|
191 |
+
skier_agent_prompt = gr.State(init_default_agent_prompt)
|
192 |
+
language_button = gr.Button("Update language")
|
193 |
+
model_type = gr.Dropdown(choices = ["Qwen/Qwen2.5-Coder-32B-Instruct", "meta-llama/Llama-3.3-70B-Instruct", "openai/gpt-4o", ],
|
194 |
+
value="Qwen/Qwen2.5-Coder-32B-Instruct",
|
195 |
+
label="Model Type",
|
196 |
+
info="If you choose openai/gpt-4o, you need to provide an API key.",
|
197 |
+
interactive=True
|
198 |
+
)
|
199 |
+
api_key_textbox = gr.Textbox(label="API Key", placeholder="Enter your API key", type="password", visible=False)
|
200 |
+
|
201 |
+
|
202 |
+
model_type.change(
|
203 |
+
lambda x: toggle_visibility(True) if x =='openai/gpt-4o' else toggle_visibility(False),
|
204 |
+
[model_type],
|
205 |
+
[api_key_textbox]
|
206 |
+
)
|
207 |
+
update_engine = gr.Button("Update LLM Engine")
|
208 |
+
|
209 |
+
|
210 |
+
stored_message = gr.State([])
|
211 |
+
chatbot = gr.Chatbot(label="Agent Thoughts", type="messages")
|
212 |
+
warning = gr.Warning("The agent can take few seconds to minutes to respond.", visible=True)
|
213 |
+
text_output = gr.Markdown(value=FINAL_MESSAGE_HEADER, container=True)
|
214 |
+
warning = gr.Markdown("⚠️ The agent can take few seconds to minutes to respond.", container=True)
|
215 |
+
text_input = gr.Textbox(lines=1, label="Chat Message", submit_btn=True, elem_classes=["custom-textbox"])
|
216 |
+
with gr.Accordion("🇬🇧 English examples"):
|
217 |
+
gr.Examples(["Can you suggest a ski touring itinerary, near Chamonix, of moderate difficulty, with good weather and safe avalanche conditions? ",
|
218 |
+
"What are current weather and avalanche conditions in the Vanoise range?"], text_input)
|
219 |
+
with gr.Accordion("🇫🇷 Exemples en français", open=False):
|
220 |
+
gr.Examples(["Poux-tu suggérer un itinéraire de ski de randonnée, près de Chamonix, d'une difficulté modérée, avec de bonnes conditions météorologiques et un risque avalanche peu élevé?",
|
221 |
+
"Quelles sont les conditions météorologiques et le risque avalanche dans le massif de la Vanoise ?"], text_input)
|
222 |
|
223 |
+
with gr.Column():
|
224 |
+
f_map = Folium(value=Map(
|
225 |
+
location=[45.9237, 6.8694],
|
226 |
+
zoom_start=10,
|
227 |
+
tiles= TileLayer(
|
228 |
+
tiles=MAP_URL,
|
229 |
+
attr="Google",
|
230 |
+
name="Google Maps",
|
231 |
+
overlay=True,
|
232 |
+
control=True )
|
233 |
+
)
|
234 |
)
|
235 |
+
|
236 |
+
df_routes = gr.State(pd.DataFrame(df_sample_routes))
|
237 |
+
data = gr.DataFrame(value=df_routes.value[["Name", "Route Link"]], datatype="markdown", interactive=False)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
238 |
|
239 |
language_button.click(lambda s: {"specific_agent_role_prompt": SKI_TOURING_ASSISTANT_PROMPT.format(language=s)}, [language], [skier_agent_prompt])
|
240 |
update_engine.click(
|
|
|
250 |
data.select(
|
251 |
update_map_on_selection, [data, df_routes],[f_map]
|
252 |
)
|
253 |
+
get_feedback_interface()
|
254 |
|
255 |
demo.launch()
|
256 |
|
src/feedback.py
ADDED
@@ -0,0 +1,54 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import datetime
|
2 |
+
import csv
|
3 |
+
import os
|
4 |
+
import huggingface_hub
|
5 |
+
from huggingface_hub import Repository
|
6 |
+
import gradio as gr
|
7 |
+
from datasets import load_dataset, DatasetDict, Dataset, concatenate_datasets
|
8 |
+
|
9 |
+
|
10 |
+
|
11 |
+
|
12 |
+
# Define the dataset repository on Hugging Face Hub
|
13 |
+
HF_DATASET_REPO = "florentgbelidji/alpine-agent-feedback"
|
14 |
+
|
15 |
+
|
16 |
+
# Load or initialize the dataset
|
17 |
+
try:
|
18 |
+
dataset = load_dataset(HF_DATASET_REPO)
|
19 |
+
except FileNotFoundError:
|
20 |
+
# Initialize an empty dataset if it doesn't exist
|
21 |
+
dataset = DatasetDict({
|
22 |
+
"train": Dataset.from_dict({
|
23 |
+
"timestamp": [datetime.datetime.now().isoformat()],
|
24 |
+
"user_feedback": ["Initial feedback"],
|
25 |
+
})
|
26 |
+
})
|
27 |
+
dataset.push_to_hub(HF_DATASET_REPO, token=os.getenv("HF_TOKEN"))
|
28 |
+
|
29 |
+
|
30 |
+
def get_feedback_interface():
|
31 |
+
with gr.Tab("Feedback Form"):
|
32 |
+
feedback_input = gr.Textbox(label="Your Feedback", lines=4, placeholder="Type your feedback here...")
|
33 |
+
submit_button = gr.Button("Submit")
|
34 |
+
feedback_response = gr.Markdown(label="feedback_response")
|
35 |
+
|
36 |
+
def add_feedback(feedback):
|
37 |
+
from datetime import datetime
|
38 |
+
|
39 |
+
# Append feedback to the dataset
|
40 |
+
new_data = {
|
41 |
+
"timestamp": [datetime.now().isoformat()],
|
42 |
+
"user_feedback": [feedback],
|
43 |
+
}
|
44 |
+
new_entry = Dataset.from_dict(new_data)
|
45 |
+
global dataset
|
46 |
+
dataset["train"] = concatenate_datasets([dataset["train"], new_entry])
|
47 |
+
|
48 |
+
# Push updated dataset to the Hub
|
49 |
+
dataset.push_to_hub(HF_DATASET_REPO)
|
50 |
+
|
51 |
+
return "Thank you for your feedback!"
|
52 |
+
|
53 |
+
submit_button.click(add_feedback, inputs=[feedback_input], outputs=[feedback_response])
|
54 |
+
|