Spaces:
Sleeping
Sleeping
done
Browse files
app.py
CHANGED
|
@@ -20,21 +20,25 @@ It is made of 2 components: *API_demo_server* and *API_demo_client*.
|
|
| 20 |
|
| 21 |
"""
|
| 22 |
|
| 23 |
-
|
| 24 |
Não sou nada.
|
| 25 |
Nunca serei nada.
|
| 26 |
Não posso querer ser nada.
|
| 27 |
À parte isso, tenho em mim todos os sonhos do mundo.
|
| 28 |
(...)
|
| 29 |
|
| 30 |
-
- Alvaro de Campos, in
|
| 31 |
"""
|
| 32 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 33 |
def get_bmc_markdown():
|
| 34 |
bmc_link = "https://www.buymeacoffee.com/nuno.tome"
|
| 35 |
image_url = "https://helloimjessa.files.wordpress.com/2021/06/bmc-button.png" # Image URL
|
| 36 |
image_size = "150" # Image size
|
| 37 |
-
image_url_full = image_url + "?w
|
| 38 |
image_link_markdown = f"[]({bmc_link})"
|
| 39 |
full_text = """
|
| 40 |
### 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!
|
|
@@ -42,10 +46,10 @@ def get_bmc_markdown():
|
|
| 42 |
return full_text
|
| 43 |
|
| 44 |
|
| 45 |
-
def send_request(
|
| 46 |
-
server = Client(
|
| 47 |
result = server.predict(
|
| 48 |
-
|
| 49 |
api_name = "/predict"
|
| 50 |
)
|
| 51 |
return result
|
|
@@ -59,17 +63,22 @@ with gr.Blocks() as demo:
|
|
| 59 |
with gr.Row():
|
| 60 |
with gr.Column():
|
| 61 |
input_text = gr.TextArea(
|
| 62 |
-
placeholder =
|
| 63 |
-
label = "**Type your message:**"
|
|
|
|
|
|
|
| 64 |
)
|
|
|
|
| 65 |
input_server = gr.Textbox(
|
| 66 |
lines = 1,
|
| 67 |
-
placeholder =
|
| 68 |
-
label = "**Type the server to call:**"
|
|
|
|
|
|
|
| 69 |
with gr.Column():
|
| 70 |
gr.Markdown("**This is your gradio api request response:**")
|
| 71 |
out = gr.JSON()
|
| 72 |
btn = gr.Button("Send request to server")
|
| 73 |
-
btn.click(fn = send_request, inputs = input_text, outputs = out)
|
| 74 |
|
| 75 |
demo.launch(share = True)
|
|
|
|
| 20 |
|
| 21 |
"""
|
| 22 |
|
| 23 |
+
INPUT_TEXT_DEFAULT = """
|
| 24 |
Não sou nada.
|
| 25 |
Nunca serei nada.
|
| 26 |
Não posso querer ser nada.
|
| 27 |
À parte isso, tenho em mim todos os sonhos do mundo.
|
| 28 |
(...)
|
| 29 |
|
| 30 |
+
- Alvaro de Campos, in Tabacaria (Fernando Pessoa)
|
| 31 |
"""
|
| 32 |
|
| 33 |
+
INPUT_SERVER_DEFAULT = "Nuno-Tome/API_demo_server"
|
| 34 |
+
|
| 35 |
+
|
| 36 |
+
|
| 37 |
def get_bmc_markdown():
|
| 38 |
bmc_link = "https://www.buymeacoffee.com/nuno.tome"
|
| 39 |
image_url = "https://helloimjessa.files.wordpress.com/2021/06/bmc-button.png" # Image URL
|
| 40 |
image_size = "150" # Image size
|
| 41 |
+
image_url_full = image_url + "?w=" + image_size
|
| 42 |
image_link_markdown = f"[]({bmc_link})"
|
| 43 |
full_text = """
|
| 44 |
### 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!
|
|
|
|
| 46 |
return full_text
|
| 47 |
|
| 48 |
|
| 49 |
+
def send_request(input_text, input_server):
|
| 50 |
+
server = Client(input_server)
|
| 51 |
result = server.predict(
|
| 52 |
+
input_text,
|
| 53 |
api_name = "/predict"
|
| 54 |
)
|
| 55 |
return result
|
|
|
|
| 63 |
with gr.Row():
|
| 64 |
with gr.Column():
|
| 65 |
input_text = gr.TextArea(
|
| 66 |
+
placeholder = INPUT_TEXT_DEFAULT,
|
| 67 |
+
label = "**Type your message:**",
|
| 68 |
+
lines = 8,
|
| 69 |
+
value = INPUT_TEXT_DEFAULT
|
| 70 |
)
|
| 71 |
+
|
| 72 |
input_server = gr.Textbox(
|
| 73 |
lines = 1,
|
| 74 |
+
placeholder = INPUT_SERVER_DEFAULT,
|
| 75 |
+
label = "**Type the server to call:**",
|
| 76 |
+
value= INPUT_SERVER_DEFAULT
|
| 77 |
+
)
|
| 78 |
with gr.Column():
|
| 79 |
gr.Markdown("**This is your gradio api request response:**")
|
| 80 |
out = gr.JSON()
|
| 81 |
btn = gr.Button("Send request to server")
|
| 82 |
+
btn.click(fn = send_request, inputs = [input_text, input_server], outputs = out)
|
| 83 |
|
| 84 |
demo.launch(share = True)
|