Nuno-Tome commited on
Commit
c942010
1 Parent(s): 3ab06d5

initial clone

Browse files
Files changed (4) hide show
  1. API_demo_client_v2.code-workspace +29 -0
  2. README.md +4 -3
  3. app.py +60 -0
  4. requirements.txt +2 -0
API_demo_client_v2.code-workspace ADDED
@@ -0,0 +1,29 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "folders": [
3
+ {
4
+ "path": "."
5
+ }
6
+ ],
7
+ "settings": {
8
+ "workbench.colorCustomizations": {
9
+ "activityBar.activeBackground": "#d0283699",
10
+ "activityBar.background": "#d0283699",
11
+ "activityBar.foreground": "#e7e7e7",
12
+ "activityBar.inactiveForeground": "#e7e7e799",
13
+ "activityBarBadge.background": "#31bb24",
14
+ "activityBarBadge.foreground": "#15202b",
15
+ "commandCenter.border": "#e7e7e799",
16
+ "sash.hoverBorder": "#d0283699",
17
+ "statusBar.background": "#a5202b99",
18
+ "statusBar.foreground": "#e7e7e7",
19
+ "statusBarItem.hoverBackground": "#d0283699",
20
+ "statusBarItem.remoteBackground": "#a5202b99",
21
+ "statusBarItem.remoteForeground": "#e7e7e7",
22
+ "titleBar.activeBackground": "#a5202b99",
23
+ "titleBar.activeForeground": "#e7e7e7",
24
+ "titleBar.inactiveBackground": "#a5202b99",
25
+ "titleBar.inactiveForeground": "#e7e7e799"
26
+ },
27
+ "peacock.color": "#a5202b99"
28
+ }
29
+ }
README.md CHANGED
@@ -1,12 +1,13 @@
1
  ---
2
  title: API Demo Client V2
3
- emoji: 🏃
4
- colorFrom: indigo
5
- colorTo: pink
6
  sdk: gradio
7
  sdk_version: 4.21.0
8
  app_file: app.py
9
  pinned: false
 
10
  ---
11
 
12
  Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
 
1
  ---
2
  title: API Demo Client V2
3
+ emoji: 🔌👩🏻‍💻
4
+ colorFrom: yellow
5
+ colorTo: red
6
  sdk: gradio
7
  sdk_version: 4.21.0
8
  app_file: app.py
9
  pinned: false
10
+ short_description: An API demo for academic purpose
11
  ---
12
 
13
  Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
app.py ADDED
@@ -0,0 +1,60 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from gradio_client import Client
3
+
4
+
5
+ DEBUG_MODE = True
6
+
7
+ MESAGE_HEADER = """
8
+ # 🔌👩🏻‍💻 API Demo (Client component) 🔌👩🏻‍💻
9
+
10
+
11
+ Welcome to my simple demonstration of the gradio potential as an API.
12
+
13
+ It is made of 2 components: *API_demo_server* and *API_demo_client*.
14
+
15
+ * Server component: 🔌🌐 [Nuno-Tome/API_demo_server](Nuno-Tome/aPI_demo_server)
16
+
17
+ * Client component: 🔌👩🏻‍💻 [Nuno-Tome/API_demo_client](Nuno-Tome/aPI_demo_client)
18
+
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"
26
+ image_url = "https://helloimjessa.files.wordpress.com/2021/06/bmc-button.png" # Image URL
27
+ image_size = "150" # Image size
28
+ image_url_full = image_url + "?w=" + image_size
29
+ image_link_markdown = f"[![Buy Me a Coffee]({image_url_full})]({bmc_link})"
30
+ full_text = """
31
+ ### 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!
32
+ # """ + image_link_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
+
44
+ with gr.Blocks() as demo:
45
+
46
+ gr.Markdown(MESAGE_HEADER)
47
+ gr.DuplicateButton()
48
+ gr.Markdown(get_bmc_markdown())
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)
requirements.txt ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ gradio_client
2
+ gradio