Ashmi Banerjee
moved the app.py
e79d81c
raw
history blame
3.88 kB
from typing import Optional
import gradio as gr
import os, sys
sys.path.append("./src")
print(os.getcwd())
from src.pipeline import pipeline
def clear():
return None, None, None
def generate_text(query_text, model_name: Optional[str], is_sustainable: Optional[bool], tokens: Optional[int] = 1024,
temp: Optional[float] = 0.49):
if is_sustainable:
sustainability = 1
else:
sustainability = 0
pipeline_response = pipeline(
query=query_text,
model_name=model_name,
sustainability= sustainability
)
return pipeline_response
examples = [["I'm planning a vacation to France. Can you suggest a one-week itinerary including must-visit places and "
"local cuisines to try?", "GPT-4"],
["I want to explore off-the-beaten-path destinations in Europe, any suggestions?", "Gemini-1.0-pro"],
["Suggest some cities that can be visited from London and are very rich in history and culture.",
"Gemini-1.0-pro"],
]
with gr.Blocks() as demo:
gr.HTML("""<center><h1 style='font-size:xx-large;'>πŸ‡ͺπŸ‡Ί Euro City Recommender using Gemini & Gemma πŸ‡ͺπŸ‡Ί</h1><br><h3>Gemini
& Gemma Sprints 2024 submissions by Ashmi Banerjee. </h3></center> <br><p>We're testing the compatibility of
Retrieval Augmented Generation (RAG) implementations with Google's <b>Gemma-2b-it</b> & <b>Gemini 1.0 Pro</b>
models through HuggingFace and VertexAI, respectively, to generate travel recommendations. This early version (read
quick and dirty implementation) aims to see if functionalities work smoothly. It relies on Wikipedia abstracts
from 160 European cities to provide answers to your questions. Please be kind with it, as it's a work in progress!
</p> <br>Google Cloud credits are provided for this project. </p>
""")
with gr.Group():
query = gr.Textbox(label="Query", placeholder="Ask for your city recommendation here!")
sustainable = gr.Checkbox(label="Sustainable", info="If you want sustainable recommendations for "
"hidden gems?")
model = gr.Dropdown(
["GPT-4", "Gemini-1.0-pro"], label="Model", info="Select your model. Will add more "
"models "
"later!",
)
output = gr.Textbox(label="Generated Results", lines=4)
with gr.Accordion("Settings", open=False):
max_new_tokens = gr.Slider(label="Max new tokens", value=1024, minimum=0, maximum=8192, step=64,
interactive=True,
visible=True, info="The maximum number of output tokens")
temperature = gr.Slider(label="Temperature", step=0.01, minimum=0.01, maximum=1.0, value=0.49,
interactive=True,
visible=True, info="The value used to module the logits distribution")
with gr.Group():
with gr.Row():
submit_btn = gr.Button("Submit", variant="primary")
clear_btn = gr.Button("Clear", variant="secondary")
cancel_btn = gr.Button("Cancel", variant="stop")
submit_btn.click(generate_text, inputs=[query, model, sustainable], outputs=[output])
clear_btn.click(clear, inputs=[], outputs=[query, model, output])
cancel_btn.click(clear, inputs=[], outputs=[query, model, output])
gr.Markdown("## Examples")
gr.Examples(
examples, inputs=[query, model], label="Examples", fn=generate_text, outputs=[output],
cache_examples=True,
)
if __name__ == "__main__":
demo.launch(show_api=False)