Spaces:
Running
Running
File size: 3,883 Bytes
4b722ec |
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 |
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) |