Spaces:
Running
Running
Ashmi Banerjee
commited on
Commit
•
32cae45
1
Parent(s):
1b399ab
updates
Browse files- app.py +2 -15
- src/text_generation/mapper.py +1 -1
- src/ui/components/actions.py +5 -4
- src/ui/components/form.py +20 -0
- src/ui/components/inputs.py +12 -10
- src/ui/components/static.py +9 -21
- src/ui/templates/__init__.py +0 -0
- src/ui/templates/example_data.py +7 -0
- src/ui/templates/intro.html +11 -4
app.py
CHANGED
@@ -1,9 +1,6 @@
|
|
1 |
import gradio as gr
|
2 |
import sys
|
3 |
-
|
4 |
-
from src.ui.components.actions import generate_text, clear
|
5 |
-
from src.ui.components.inputs import main_component
|
6 |
-
from src.ui.components.static import load_buttons, load_examples, model_settings
|
7 |
from src.ui.setup import load_html_from_file
|
8 |
from src.text_generation.vertexai_setup import initialize_vertexai_params
|
9 |
|
@@ -21,17 +18,7 @@ def create_ui():
|
|
21 |
with gr.Blocks(
|
22 |
theme=gr.themes.Default(primary_hue=gr.themes.colors.green, secondary_hue=gr.themes.colors.blue)) as app:
|
23 |
gr.HTML(html_content)
|
24 |
-
|
25 |
-
output = gr.Textbox(label="Generated Results", lines=4)
|
26 |
-
max_new_tokens, temperature = model_settings()
|
27 |
-
|
28 |
-
# Load the buttons for the interface
|
29 |
-
load_buttons(country, starting_point, query, sustainable, model,
|
30 |
-
max_new_tokens, temperature,
|
31 |
-
output,
|
32 |
-
generate_text_fn=generate_text,
|
33 |
-
clear_fn=clear)
|
34 |
-
load_examples(country, starting_point, query, sustainable, model, output, generate_text)
|
35 |
|
36 |
return app
|
37 |
|
|
|
1 |
import gradio as gr
|
2 |
import sys
|
3 |
+
from src.ui.components.form import form_block
|
|
|
|
|
|
|
4 |
from src.ui.setup import load_html_from_file
|
5 |
from src.text_generation.vertexai_setup import initialize_vertexai_params
|
6 |
|
|
|
18 |
with gr.Blocks(
|
19 |
theme=gr.themes.Default(primary_hue=gr.themes.colors.green, secondary_hue=gr.themes.colors.blue)) as app:
|
20 |
gr.HTML(html_content)
|
21 |
+
form_block()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
22 |
|
23 |
return app
|
24 |
|
src/text_generation/mapper.py
CHANGED
@@ -1,7 +1,7 @@
|
|
1 |
MODEL_MAPPER = {
|
2 |
-
"Gemini-1.0-pro": "gemini-1.0-pro",
|
3 |
"Gemini-1.5-Flash": "gemini-1.5-flash-001",
|
4 |
"Gemini-1.5-Pro": "gemini-1.5-pro-001",
|
|
|
5 |
'Gemma-2-9B-it': "google/gemma-2-9b-it",
|
6 |
'Gemma-2-2B-it': "google/gemma-2-2b-it",
|
7 |
"Claude3.5-sonnet": "claude-3-5-sonnet@20240620",
|
|
|
1 |
MODEL_MAPPER = {
|
|
|
2 |
"Gemini-1.5-Flash": "gemini-1.5-flash-001",
|
3 |
"Gemini-1.5-Pro": "gemini-1.5-pro-001",
|
4 |
+
"Gemini-1.0-pro": "gemini-1.0-pro",
|
5 |
'Gemma-2-9B-it': "google/gemma-2-9b-it",
|
6 |
'Gemma-2-2B-it': "google/gemma-2-2b-it",
|
7 |
"Claude3.5-sonnet": "claude-3-5-sonnet@20240620",
|
src/ui/components/actions.py
CHANGED
@@ -3,16 +3,17 @@ from typing import Optional
|
|
3 |
from src.pipeline import pipeline
|
4 |
|
5 |
|
6 |
-
|
7 |
-
|
|
|
8 |
|
9 |
|
10 |
def generate_text(
|
11 |
country: Optional[str],
|
12 |
starting_point: Optional[str],
|
13 |
query_text: str,
|
14 |
-
is_sustainable: Optional[bool],
|
15 |
-
model: Optional[str],
|
16 |
max_tokens: Optional[int] = 1024,
|
17 |
temp: Optional[float] = 0.49,
|
18 |
):
|
|
|
3 |
from src.pipeline import pipeline
|
4 |
|
5 |
|
6 |
+
# Define the clear function dynamically based on the number of inputs
|
7 |
+
def clear(*args):
|
8 |
+
return tuple([None] * len(args)) # Return None for each input/output component dynamically
|
9 |
|
10 |
|
11 |
def generate_text(
|
12 |
country: Optional[str],
|
13 |
starting_point: Optional[str],
|
14 |
query_text: str,
|
15 |
+
is_sustainable: Optional[bool] = True,
|
16 |
+
model: Optional[str] = "Gemini-1.5-Pro",
|
17 |
max_tokens: Optional[int] = 1024,
|
18 |
temp: Optional[float] = 0.49,
|
19 |
):
|
src/ui/components/form.py
ADDED
@@ -0,0 +1,20 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
|
3 |
+
from src.ui.components.actions import generate_text, clear
|
4 |
+
from src.ui.components.inputs import main_component
|
5 |
+
from src.ui.components.static import model_settings, load_buttons, load_examples
|
6 |
+
|
7 |
+
|
8 |
+
def form_block():
|
9 |
+
country, starting_point, query, model = main_component()
|
10 |
+
output = gr.Textbox(label="Your recommendations are sustainable with respect to the environment, your starting "
|
11 |
+
"location, and month of travel.", lines=4)
|
12 |
+
max_new_tokens, temperature = model_settings()
|
13 |
+
|
14 |
+
# Load the buttons for the interface
|
15 |
+
load_buttons(country, starting_point, query, model,
|
16 |
+
max_new_tokens, temperature,
|
17 |
+
output,
|
18 |
+
generate_text_fn=generate_text,
|
19 |
+
clear_fn=clear)
|
20 |
+
load_examples(country, starting_point, query, model, output, generate_text)
|
src/ui/components/inputs.py
CHANGED
@@ -21,7 +21,7 @@ def update_cities(selected_country, df):
|
|
21 |
return gr.Dropdown(choices=filtered_cities, interactive=True)
|
22 |
|
23 |
|
24 |
-
def main_component() -> Tuple[gr.Dropdown, gr.Dropdown, gr.Textbox, gr.
|
25 |
"""
|
26 |
Creates the main Gradio interface components and returns them.
|
27 |
|
@@ -53,22 +53,24 @@ def main_component() -> Tuple[gr.Dropdown, gr.Dropdown, gr.Textbox, gr.Checkbox,
|
|
53 |
)
|
54 |
|
55 |
# User query input
|
56 |
-
query = gr.Textbox(label="
|
|
|
|
|
57 |
|
58 |
# Checkbox for sustainable travel option
|
59 |
-
sustainable = gr.Checkbox(
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
)
|
64 |
|
65 |
-
models = list(MODEL_MAPPER.keys())[:
|
66 |
# Model selection dropdown
|
67 |
model = gr.Dropdown(
|
68 |
choices=models,
|
69 |
label="Model",
|
70 |
-
info="Select your model. The model will generate
|
71 |
)
|
72 |
|
73 |
# Return all the components individually
|
74 |
-
return country, starting_point, query,
|
|
|
21 |
return gr.Dropdown(choices=filtered_cities, interactive=True)
|
22 |
|
23 |
|
24 |
+
def main_component() -> Tuple[gr.Dropdown, gr.Dropdown, gr.Textbox, gr.Dropdown]:
|
25 |
"""
|
26 |
Creates the main Gradio interface components and returns them.
|
27 |
|
|
|
53 |
)
|
54 |
|
55 |
# User query input
|
56 |
+
query = gr.Textbox(label="Enter your preferences e.g. beaches, night life etc. and ask for your "
|
57 |
+
"recommendation for European cities!", placeholder="Ask for your city recommendation"
|
58 |
+
" here!")
|
59 |
|
60 |
# Checkbox for sustainable travel option
|
61 |
+
# sustainable = gr.Checkbox(
|
62 |
+
# label="Sustainable",
|
63 |
+
# info="Do you want your recommendations to be sustainable with regards to the environment, "
|
64 |
+
# "your starting location, and month of travel?"
|
65 |
+
# )
|
66 |
|
67 |
+
models = list(MODEL_MAPPER.keys())[:2]
|
68 |
# Model selection dropdown
|
69 |
model = gr.Dropdown(
|
70 |
choices=models,
|
71 |
label="Model",
|
72 |
+
info="Select your model. The model will generate sustainable recommendations based on your query."
|
73 |
)
|
74 |
|
75 |
# Return all the components individually
|
76 |
+
return country, starting_point, query, model
|
src/ui/components/static.py
CHANGED
@@ -3,17 +3,13 @@ from typing import Callable, Tuple, Optional
|
|
3 |
import gradio as gr
|
4 |
|
5 |
from src.ui.components.inputs import get_places, update_cities, main_component
|
6 |
-
|
7 |
-
|
8 |
-
def show_examples(examples):
|
9 |
-
return gr.Dataset(samples=examples)
|
10 |
|
11 |
|
12 |
def load_examples(
|
13 |
country: gr.components.Component,
|
14 |
starting_point: gr.components.Component,
|
15 |
query: gr.components.Component,
|
16 |
-
sustainable: gr.components.Component,
|
17 |
model: gr.components.Component,
|
18 |
output: gr.components.Component,
|
19 |
generate_text_fn: Callable[
|
@@ -23,17 +19,10 @@ def load_examples(
|
|
23 |
# Load the places data
|
24 |
df = get_places()
|
25 |
# Provide examples
|
26 |
-
example_data =
|
27 |
-
["Austria", "Vienna",
|
28 |
-
"I'm planning a trip in July and enjoy beaches, nightlife, and vibrant cities. Recommend some cities.",
|
29 |
-
True, "Gemini-1.0-pro"],
|
30 |
-
["Germany", "Berlin",
|
31 |
-
"For winter travel, can you recommend destinations for Christmas markets? I love festive atmospheres.", False,
|
32 |
-
"Gemini-1.5-Pro"],
|
33 |
-
]
|
34 |
gr.Examples(
|
35 |
examples=example_data,
|
36 |
-
inputs=[country, starting_point, query,
|
37 |
fn=generate_text_fn,
|
38 |
outputs=[output],
|
39 |
cache_examples=True,
|
@@ -51,7 +40,6 @@ def load_buttons(
|
|
51 |
starting_point: gr.components.Component,
|
52 |
query: gr.components.Component,
|
53 |
model: gr.components.Component,
|
54 |
-
sustainable: gr.components.Component,
|
55 |
max_new_tokens: gr.components.Component,
|
56 |
temperature: gr.components.Component,
|
57 |
output: gr.components.Component,
|
@@ -80,27 +68,27 @@ def load_buttons(
|
|
80 |
"""
|
81 |
with gr.Group() as btns:
|
82 |
with gr.Row():
|
83 |
-
submit_btn = gr.Button("
|
84 |
clear_btn = gr.Button("Clear", variant="secondary")
|
85 |
cancel_btn = gr.Button("Cancel", variant="stop")
|
86 |
|
87 |
# Bind actions to the buttons
|
88 |
submit_btn.click(
|
89 |
fn=generate_text_fn, # Function to generate text
|
90 |
-
inputs=[query, model,
|
91 |
starting_point, max_new_tokens,
|
92 |
temperature], # Input components for generation
|
93 |
outputs=[output] # Output component
|
94 |
)
|
95 |
clear_btn.click(
|
96 |
fn=clear_fn, # Function to clear inputs
|
97 |
-
inputs=[], #
|
98 |
-
outputs=[query, model,
|
99 |
)
|
100 |
cancel_btn.click(
|
101 |
fn=clear_fn, # Function to cancel and clear inputs
|
102 |
-
inputs=[], #
|
103 |
-
outputs=[query, model,
|
104 |
)
|
105 |
return btns
|
106 |
|
|
|
3 |
import gradio as gr
|
4 |
|
5 |
from src.ui.components.inputs import get_places, update_cities, main_component
|
6 |
+
from src.ui.templates.example_data import EXAMPLES
|
|
|
|
|
|
|
7 |
|
8 |
|
9 |
def load_examples(
|
10 |
country: gr.components.Component,
|
11 |
starting_point: gr.components.Component,
|
12 |
query: gr.components.Component,
|
|
|
13 |
model: gr.components.Component,
|
14 |
output: gr.components.Component,
|
15 |
generate_text_fn: Callable[
|
|
|
19 |
# Load the places data
|
20 |
df = get_places()
|
21 |
# Provide examples
|
22 |
+
example_data = EXAMPLES
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
23 |
gr.Examples(
|
24 |
examples=example_data,
|
25 |
+
inputs=[country, starting_point, query, model],
|
26 |
fn=generate_text_fn,
|
27 |
outputs=[output],
|
28 |
cache_examples=True,
|
|
|
40 |
starting_point: gr.components.Component,
|
41 |
query: gr.components.Component,
|
42 |
model: gr.components.Component,
|
|
|
43 |
max_new_tokens: gr.components.Component,
|
44 |
temperature: gr.components.Component,
|
45 |
output: gr.components.Component,
|
|
|
68 |
"""
|
69 |
with gr.Group() as btns:
|
70 |
with gr.Row():
|
71 |
+
submit_btn = gr.Button("Search", variant="primary")
|
72 |
clear_btn = gr.Button("Clear", variant="secondary")
|
73 |
cancel_btn = gr.Button("Cancel", variant="stop")
|
74 |
|
75 |
# Bind actions to the buttons
|
76 |
submit_btn.click(
|
77 |
fn=generate_text_fn, # Function to generate text
|
78 |
+
inputs=[query, model,
|
79 |
starting_point, max_new_tokens,
|
80 |
temperature], # Input components for generation
|
81 |
outputs=[output] # Output component
|
82 |
)
|
83 |
clear_btn.click(
|
84 |
fn=clear_fn, # Function to clear inputs
|
85 |
+
inputs=[query, model, starting_point, country, output], # inputs for clearing
|
86 |
+
outputs=[query, model, starting_point, country, output] # Clear all inputs and output
|
87 |
)
|
88 |
cancel_btn.click(
|
89 |
fn=clear_fn, # Function to cancel and clear inputs
|
90 |
+
inputs=[query, model, starting_point, country, output], #inputs for cancel
|
91 |
+
outputs=[query, model, starting_point, country, output] # Clear all inputs and output
|
92 |
)
|
93 |
return btns
|
94 |
|
src/ui/templates/__init__.py
ADDED
File without changes
|
src/ui/templates/example_data.py
ADDED
@@ -0,0 +1,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
EXAMPLES = [
|
2 |
+
["Austria", "Vienna",
|
3 |
+
"I'm planning a trip in July and enjoy beaches, nightlife, and vibrant cities. Recommend some cities.", "Gemini-1.5-Flash"],
|
4 |
+
["Germany", "Berlin",
|
5 |
+
"For winter travel, can you recommend destinations for Christmas markets? I love festive atmospheres.",
|
6 |
+
"Gemini-1.5-Pro"],
|
7 |
+
]
|
src/ui/templates/intro.html
CHANGED
@@ -32,11 +32,18 @@
|
|
32 |
The vector embeddings are stored and accessed in a VectorDB (LanceDB) hosted in Google Cloud.
|
33 |
</p>
|
34 |
|
35 |
-
<p style="text-align: justify">This is an extension of the work
|
36 |
-
|
37 |
-
<
|
|
|
|
|
|
|
|
|
|
|
38 |
<blockquote>
|
39 |
-
<p>
|
|
|
|
|
40 |
</blockquote>
|
41 |
<br>
|
42 |
<p style="text-align: justify; font-weight: bold"><sup>*</sup>Google Cloud credits are provided for this project.</p>
|
|
|
32 |
The vector embeddings are stored and accessed in a VectorDB (LanceDB) hosted in Google Cloud.
|
33 |
</p>
|
34 |
|
35 |
+
<p style="text-align: justify">This is an extension of the following work. To <b>cite</b>, please use the following:</p>
|
36 |
+
|
37 |
+
<blockquote>
|
38 |
+
<p> [1] <b>Enhancing sustainability in Tourism Recommender Systems,</b> <i>Ashmi Banerjee, Adithi Satish, Wolfgang
|
39 |
+
Wörndl</i>, In Proceedings of the 1st International Workshop on Recommender Systems for Sustainability and Social
|
40 |
+
Good (RecSoGood 2024), co-located with ACM RecSys 2024, Bari, Italy.
|
41 |
+
</p>
|
42 |
+
</blockquote>
|
43 |
<blockquote>
|
44 |
+
<p> [2] <b>Modeling Sustainable City Trips: Integrating CO2e Emissions, Popularity, and Seasonality into Tourism Recommender Systems,</b> <i>Ashmi Banerjee, Tunar Mahmudov, Emil Adler, Fitri Nur Aisyah, Wolfgang
|
45 |
+
Wörndl</i>, arXiv preprint <a href="https://arxiv.org/abs/2403.18604">arXiv:2403.18604 (2024)</a>.
|
46 |
+
</p>
|
47 |
</blockquote>
|
48 |
<br>
|
49 |
<p style="text-align: justify; font-weight: bold"><sup>*</sup>Google Cloud credits are provided for this project.</p>
|