ldhldh commited on
Commit
e47bcc0
·
1 Parent(s): 9288562

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +39 -35
app.py CHANGED
@@ -59,41 +59,45 @@ def yn(x):
59
  )
60
  return result
61
 
62
-
63
-
64
- with gr.Blocks() as blk:
65
- gr.Markdown("# Gradio Blocks (3.0) with REST API")
66
- t = gr.Textbox(label="User input")
67
- c = gr.Button("mbti")
68
- b = gr.Button("chat")
69
- a = gr.Button("yn")
70
- o = gr.Textbox(label="Model output")
71
- gr.Markdown("""
72
- ## API
73
- Can select which function to use by passing in `fn_index`:
74
- ```python
75
- import requests
76
- requests.post(
77
- url="https://hf.space/embed/versae/gradio-blocks-rest-api/+/api/predict/", json={"data": ["Jessie"], "fn_index": 0}
78
- ).json()
79
- requests.post(
80
- url="https://hf.space/embed/versae/gradio-blocks-rest-api/+/api/predict/", json={"data": ["Jessie"], "fn_index": 1}
81
- ).json()
82
- ```
83
- Or using cURL
84
- ```
85
- $ 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}'
86
- $ 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}'
87
- ```""")
88
 
89
- c.click(mbti, inputs=[t], outputs=[o])
90
- b.click(chat, inputs=[t], outputs=[o])
91
- a.click(yn, inputs=[t], outputs=[o])
92
- ifa = gr.Interface(lambda: None, inputs=[t], outputs=[o])
 
 
 
 
 
 
 
 
 
93
 
94
- blk.input_components = ifa.input_components
95
- blk.output_components = ifa.output_components
96
- blk.examples = None
97
- blk.predict_durations = []
 
 
 
 
 
 
 
 
 
98
 
99
- bapp = blk.launch()
 
 
 
 
 
 
 
 
 
 
 
 
 
59
  )
60
  return result
61
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
62
 
63
+ aa = gradio.Interface(
64
+ fn=yn,
65
+ inputs="text",
66
+ outputs="text",
67
+ examples=[
68
+ ["Jill"],
69
+ ["Sam"]
70
+ ],
71
+ title="REST API with Gradio and Huggingface Spaces",
72
+ description="This is a demo of how to build an AI powered REST API with Gradio and Huggingface Spaces – for free! Based on [this article](https://www.tomsoderlund.com/ai/building-ai-powered-rest-api). See the **Use via API** link at the bottom of this page.",
73
+ article="© Tom Söderlund 2022"
74
+ )
75
+ aa.launch()
76
 
77
+ bb = gradio.Interface(
78
+ fn=chat,
79
+ inputs="text",
80
+ outputs="text",
81
+ examples=[
82
+ ["Jill"],
83
+ ["Sam"]
84
+ ],
85
+ title="REST API with Gradio and Huggingface Spaces",
86
+ description="This is a demo of how to build an AI powered REST API with Gradio and Huggingface Spaces – for free! Based on [this article](https://www.tomsoderlund.com/ai/building-ai-powered-rest-api). See the **Use via API** link at the bottom of this page.",
87
+ article="© Tom Söderlund 2022"
88
+ )
89
+ bb.launch()
90
 
91
+ cc = gradio.Interface(
92
+ fn=mbti,
93
+ inputs="text",
94
+ outputs="text",
95
+ examples=[
96
+ ["Jill"],
97
+ ["Sam"]
98
+ ],
99
+ title="REST API with Gradio and Huggingface Spaces",
100
+ description="This is a demo of how to build an AI powered REST API with Gradio and Huggingface Spaces – for free! Based on [this article](https://www.tomsoderlund.com/ai/building-ai-powered-rest-api). See the **Use via API** link at the bottom of this page.",
101
+ article="© Tom Söderlund 2022"
102
+ )
103
+ cc.launch()