File size: 1,560 Bytes
62f3442
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import gradio as gr

# Sample classes
class ResultA:
    def __init__(self, query):
        self.response = f"Result from Function A for query: {query}"

class ResultB:
    def __init__(self, query):
        self.response = f"Result from Function B for query: {query}"

class ResultC:
    def __init__(self, query):
        self.response = f"Result from Function C for query: {query}"

# Functions that return class instances
def function_a(query):
    return ResultA(query)

def function_b(query):
    return ResultB(query)

def function_c(query):
    return ResultC(query)

# Function to handle user input
def handle_query(function_choice, query):
    function_map = {
        "Function A": function_a,
        "Function B": function_b,
        "Function C": function_c,
    }
    
    if function_choice in function_map:
        result = function_map[function_choice](query)
        return result.response
    else:
        return "Invalid selection."

# Gradio Interface
iface = gr.Interface(
    fn=handle_query,
    inputs=[
        gr.Radio(["Function A", "Function B", "Function C"], label="Select Function"),
        gr.Textbox(label="Enter Query")
    ],
    outputs=gr.Textbox(label="Response"),
    title="Function Selector",
    description="Select a function, enter a query, and get a response.",
        # Adding footer details
    article="""
    **About this application:**
    This tool allows users to select a function, input a query, and get a response based on the selected function.
    Developed using Gradio.
    """
)

iface.launch()