Nuno-Tome commited on
Commit
c8389d7
2 Parent(s): b106dfa ba72ecb

Merge branch 'feature/add_server_input' into develop

Browse files
Files changed (1) hide show
  1. app.py +34 -10
app.py CHANGED
@@ -19,7 +19,20 @@ It is made of 2 components: *API_demo_server* and *API_demo_client*.
19
  **Just write you message and watch it be returned by the server.**
20
 
21
  """
22
-
 
 
 
 
 
 
 
 
 
 
 
 
 
23
 
24
  def get_bmc_markdown():
25
  bmc_link = "https://www.buymeacoffee.com/nuno.tome"
@@ -33,11 +46,11 @@ def get_bmc_markdown():
33
  return full_text
34
 
35
 
36
- def send_request(text):
37
- client = Client("Nuno-Tome/API_demo_server")
38
- result = client.predict(
39
- text,
40
- api_name="/predict"
41
  )
42
  return result
43
 
@@ -49,12 +62,23 @@ with gr.Blocks() as demo:
49
 
50
  with gr.Row():
51
  with gr.Column():
52
- gr.Markdown("**Type your message:**")
53
- inp = gr.TextArea(placeholder="What is your name?")
 
 
 
 
 
 
 
 
 
 
 
54
  with gr.Column():
55
  gr.Markdown("**This is your gradio api request response:**")
56
  out = gr.JSON()
57
  btn = gr.Button("Send request to server")
58
- btn.click(fn=send_request, inputs=inp, outputs=out)
59
 
60
- demo.launch(share=True)
 
19
  **Just write you message and watch it be returned by the server.**
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"
 
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
56
 
 
62
 
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)