File size: 1,476 Bytes
afd4f00
 
e424ebb
afd4f00
 
e424ebb
afd4f00
e424ebb
 
 
afd4f00
e424ebb
afd4f00
 
e424ebb
afd4f00
e424ebb
afd4f00
e424ebb
afd4f00
 
 
860dc0f
 
 
e424ebb
860dc0f
 
 
 
 
 
 
 
 
 
 
 
 
e424ebb
 
860dc0f
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
import gradio as gr

def create_greeting_message(user_name: str, tone: str) -> str:
    """
    Creates a friendly or hostile user message for a user
    
    Args:
        user_name (str): the name of the user that needs a greeting message
        tone (str): choose between "friendly" and "hostile"
    
    Returns:
        str: A string with the user message
    """
    if tone == "friendly":
        greeting_msg = "Great to have you here " + user_name
    elif tone == "hostile":
        greeting_msg = "Ehm, soo cool to have you here " + user_name
    else:
        greeting_msg = "wrong argument for tone"
    
    return greeting_msg

# Explicitly define the API function
def api_create_greeting(user_name, tone):
    return create_greeting_message(user_name, tone)

with gr.Blocks() as demo:
    with gr.Row():
        with gr.Column():
            gr.Markdown("# Create User Greetings")
            user_name = gr.Textbox(label="user_name", placeholder="Enter your name")
            tone = gr.Textbox(label="tone", placeholder="Enter friendly or hostile")
            result = gr.Textbox(label="Result")
            btn = gr.Button("Generate Greeting")
            btn.click(fn=create_greeting_message, inputs=[user_name, tone], outputs=result)
    
    # Explicitly define API endpoints
    demo.queue()
    demo.add_api_route("/create_greeting", api_create_greeting, methods=["POST"])

if __name__ == "__main__":
    demo.launch(mcp_server=True, ssr_mode=False)