File size: 2,026 Bytes
efa8259
e45a3e3
 
efa8259
e45a3e3
 
 
 
9181a43
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3ae23bf
 
 
 
 
4c753a1
 
3ae23bf
 
9181a43
 
 
 
 
 
 
 
 
 
 
 
 
e45a3e3
 
9181a43
 
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

import gradio as gr
from smolagents import load_tool

# Load the tool
journey_tool = load_tool("MHamdan/journey-metrics-tool", trust_remote_code=True)

def create_interface():
    with gr.Blocks(title="Journey Metrics Calculator") as iface:
        gr.Markdown("# Journey Metrics Calculator")
        gr.Markdown("Calculate travel distance and time between two locations.")
        
        with gr.Row():
            with gr.Column():
                start = gr.Textbox(
                    label="Start Location",
                    placeholder="e.g., Montreal"
                )
                dest = gr.Textbox(
                    label="Destination Location",
                    placeholder="e.g., Toronto"
                )
                mode = gr.Dropdown(
                    choices=["driving", "walking", "bicycling", "transit", "plane"],
                    label="Transportation Mode",
                    value="driving"
                )
                submit_btn = gr.Button("Calculate Journey")
                
            with gr.Column():
                output = gr.Textbox(
                    label="Journey Details",
                    lines=5
                )
        
        # Example data
        gr.Examples(
            examples=[
            ["Montreal", "Toronto", "plane"],
            ["Vancouver", "Whistler", "driving"],
            ["Ottawa", "Kingston", "bicycling"],
            ["New York", "Los Angeles", "plane"],
            ["Sanaa", "Jeddah", "plane"],
            ["Sanaa", "Jeddah", "driving"],
            ["Sanaa", "Jeddah", "bicycling"],
            ["London", "Paris", "train"]
        ],
            inputs=[start, dest, mode],
            outputs=output,
            fn=journey_tool,
            cache_examples=True
        )
        
        submit_btn.click(
            fn=journey_tool,
            inputs=[start, dest, mode],
            outputs=output
        )
    
    return iface

# Create and launch the interface
demo = create_interface()
demo.launch()