File size: 1,137 Bytes
900795e
936b827
 
 
 
900795e
936b827
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
900795e
936b827
 
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
import gradio as gr
import os
from dotenv import load_dotenv
import serpapi
load_dotenv()

def search_flights(departure_id: str, arrival_id: str, outbound_date: str, return_date: str, currency: str):
    """
    Uses Google Flights API to search for flights, giving price insights, best flights and airport information 
    params:
        departure_id (str): The departure airport IATA code.
        arrival_id (str): The arrival airport IATA code.
        outbound_date (str): The outbound date in YYYY-MM-DD format.
        return_date (str): The return date in YYYY-MM-DD format.
        currency (str): The currency code.
    """
    params = {
        "engine": "google_flights",
        "departure_id": departure_id,
        "arrival_id": arrival_id,
        "outbound_date": outbound_date,
        "return_date": return_date,
        "currency": currency,
        "hl": "en",
        "api_key": os.getenv("SERP_API_KEY"),
    }
    result = serpapi.search(params)
    return result.as_dict()

demo = gr.Interface(fn=search_flights, inputs=["text", "text", "text", "text", "text"], outputs=gr.JSON())
demo.launch(mcp_server=True)