File size: 2,127 Bytes
c942010
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
b106dfa
c942010
 
 
 
 
 
 
 
 
 
 
 
 
 
9ad6428
 
c942010
 
 
 
 
 
 
 
 
 
 
 
 
9ad6428
 
 
 
 
 
 
 
 
c942010
 
 
 
9ad6428
c942010
 
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
66
67
import gradio as gr
from gradio_client import Client


DEBUG_MODE = True

MESAGE_HEADER = """
# 🔌👩🏻‍💻  API Demo (Client component)  🔌👩🏻‍💻


Welcome to my simple demonstration of the gradio potential as an API.

It is made of 2 components: *API_demo_server* and *API_demo_client*.

* Server component: 🔌🌐 [Nuno-Tome/API_demo_server](Nuno-Tome/aPI_demo_server)

* Client component: 🔌👩🏻‍💻 [Nuno-Tome/API_demo_client](Nuno-Tome/aPI_demo_client)

**Just write you message and watch it be returned by the server.**   
                
"""
 

def get_bmc_markdown():
    bmc_link = "https://www.buymeacoffee.com/nuno.tome"
    image_url = "https://helloimjessa.files.wordpress.com/2021/06/bmc-button.png" # Image URL
    image_size = "150" # Image size
    image_url_full = image_url + "?w=" + image_size
    image_link_markdown = f"[![Buy Me a Coffee]({image_url_full})]({bmc_link})"
    full_text = """
                ### If you like this project, please consider liking it or buying me a coffee. It will help me to keep working on this and other projects. Thank you!
                # """ + image_link_markdown
    return full_text

   
def send_request(text):
    server = Client("Nuno-Tome/API_demo_server") 
    result = server.predict(
        text,
        api_name="/predict"
    )
    return result

with gr.Blocks() as demo:
  
    gr.Markdown(MESAGE_HEADER)
    gr.DuplicateButton()
    gr.Markdown(get_bmc_markdown())
     
    with gr.Row():
        with gr.Column():
            input_text = gr.TextArea(
                placeholder="What is your name?",  
                label= "**Type your message:**"
                )
            input_server = gr.Textbox(
                lines = 1, 
                placeholder = "Server URL", 
                label= "**Type the server to call:**"
                )
        with gr.Column():
            gr.Markdown("**This is your gradio api request response:**")
            out = gr.JSON()  
    btn = gr.Button("Send request to server")
    btn.click(fn=send_request, inputs=input_text, outputs=out)
 
demo.launch(share=True)