yozozaya commited on
Commit
e005139
·
1 Parent(s): ce74bb4

test as an API

Browse files
Files changed (1) hide show
  1. app.py +18 -18
app.py CHANGED
@@ -30,33 +30,33 @@ def hadet(x):
30
  return f"Hadet, {x}"
31
 
32
  with gr.Blocks() as blk:
33
- gr.Markdown("# Gradio Blocks (3.0) with REST API")
34
  t = gr.Textbox()
35
  b = gr.Button("Hallo")
36
  a = gr.Button("Hadet")
37
  o = gr.Textbox()
38
  b.click(hallo, inputs=[t], outputs=[o])
39
  a.click(hadet, inputs=[t], outputs=[o])
40
- gr.Markdown("""
41
- ## API
42
- Can select which function to use by passing in `fn_index`:
43
- ```python
44
- import requests
45
 
46
- requests.post(
47
- url="https://hf.space/embed/versae/gradio-blocks-rest-api/+/api/predict/", json={"data": ["Jessie"], "fn_index": 0}
48
- ).json()
49
- requests.post(
50
- url="https://hf.space/embed/versae/gradio-blocks-rest-api/+/api/predict/", json={"data": ["Jessie"], "fn_index": 1}
51
- ).json()
52
- ```
53
 
54
- Or using cURL
55
 
56
- ```
57
- $ curl -X POST https://hf.space/embed/versae/gradio-blocks-rest-api/+/api/predict/ -H 'Content-Type: application/json' -d '{"data": ["Jessie"], "fn_index": 0}'
58
- $ curl -X POST https://hf.space/embed/versae/gradio-blocks-rest-api/+/api/predict/ -H 'Content-Type: application/json' -d '{"data": ["Jessie"], "fn_index": 1}'
59
- ```""")
60
 
61
  ifa = gr.Interface(lambda: None, inputs=[t], outputs=[o])
62
 
 
30
  return f"Hadet, {x}"
31
 
32
  with gr.Blocks() as blk:
33
+ # gr.Markdown("# Gradio Blocks (3.0) with REST API")
34
  t = gr.Textbox()
35
  b = gr.Button("Hallo")
36
  a = gr.Button("Hadet")
37
  o = gr.Textbox()
38
  b.click(hallo, inputs=[t], outputs=[o])
39
  a.click(hadet, inputs=[t], outputs=[o])
40
+ # gr.Markdown("""
41
+ # ## API
42
+ # Can select which function to use by passing in `fn_index`:
43
+ # ```python
44
+ # import requests
45
 
46
+ # requests.post(
47
+ # url="https://hf.space/embed/versae/gradio-blocks-rest-api/+/api/predict/", json={"data": ["Jessie"], "fn_index": 0}
48
+ # ).json()
49
+ # requests.post(
50
+ # url="https://hf.space/embed/versae/gradio-blocks-rest-api/+/api/predict/", json={"data": ["Jessie"], "fn_index": 1}
51
+ # ).json()
52
+ # ```
53
 
54
+ # Or using cURL
55
 
56
+ # ```
57
+ # $ curl -X POST https://hf.space/embed/versae/gradio-blocks-rest-api/+/api/predict/ -H 'Content-Type: application/json' -d '{"data": ["Jessie"], "fn_index": 0}'
58
+ # $ curl -X POST https://hf.space/embed/versae/gradio-blocks-rest-api/+/api/predict/ -H 'Content-Type: application/json' -d '{"data": ["Jessie"], "fn_index": 1}'
59
+ # ```""")
60
 
61
  ifa = gr.Interface(lambda: None, inputs=[t], outputs=[o])
62