File size: 1,422 Bytes
b216cb2
06bbd1d
 
b216cb2
06bbd1d
 
 
 
 
 
 
 
 
 
 
b216cb2
06bbd1d
 
 
 
 
 
 
 
 
 
 
 
 
464d0c9
 
b216cb2
 
 
 
464d0c9
 
 
b216cb2
03a68e7
4f7c60f
b216cb2
 
464d0c9
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
import gradio as gr
from langchain_experimental.llms.ollama_functions import OllamaFunctions

# Initialize the Ollama model
model = OllamaFunctions(model="gemma:7b")
model = model.bind(
    functions=[
        {
            "name": "get_current_weather",
            "description": "Get the current weather in a given location",
            "parameters": {
                "type": "object",
                "properties": {
                    "location": {
                        "type": "string",
                        "description": "The city and state, e.g., San Francisco, CA",
                    },
                    "unit": {
                        "type": "string",
                        "enum": ["celsius", "fahrenheit"],
                    },
                },
                "required": ["location"],
            },
        }
    ],
    function_call={"name": "get_current_weather"},
)

def get_weather(location, unit):
    user_input = f"{location}, {unit}"
    result = model.invoke(user_input)
    return result

iface = gr.Interface(
    fn=get_weather,
    inputs=[gr.Textbox(label="Location (e.g., 'San Francisco, CA')"), gr.Radio(choices=["celsius", "fahrenheit"], label="Unit")],
    outputs=gr.Text(label="Weather Information"),
    title="Weather Information",
    description="Enter a location and select the unit to get the current weather.",
    allow_flagging="never"
)

iface.launch()