Nipun commited on
Commit
0b70e0a
·
1 Parent(s): 18862b5

Add API usage examples to web app

Browse files
Files changed (1) hide show
  1. app/main.py +43 -0
app/main.py CHANGED
@@ -51,6 +51,49 @@ def read_root():
51
 
52
  <div id="result"></div>
53
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
54
  <script>
55
  async function predict() {
56
  const data = {
 
51
 
52
  <div id="result"></div>
53
 
54
+ <div style="margin-top: 40px; border-top: 1px solid #eee; padding-top: 20px;">
55
+ <h2>API Usage</h2>
56
+ <p>You can also access this model via the API.</p>
57
+
58
+ <h3>cURL</h3>
59
+ <pre style="background: #f4f4f4; padding: 10px; border-radius: 5px; overflow-x: auto;">
60
+ curl -X POST "https://nipun-ml-deploy-app.hf.space/predict" \
61
+ -H "Content-Type: application/json" \
62
+ -d '{"sepal_length": 5.1, "sepal_width": 3.5, "petal_length": 1.4, "petal_width": 0.2}'</pre>
63
+
64
+ <h3>Python</h3>
65
+ <pre style="background: #f4f4f4; padding: 10px; border-radius: 5px; overflow-x: auto;">
66
+ import requests
67
+
68
+ url = "https://nipun-ml-deploy-app.hf.space/predict"
69
+ data = {
70
+ "sepal_length": 5.1,
71
+ "sepal_width": 3.5,
72
+ "petal_length": 1.4,
73
+ "petal_width": 0.2
74
+ }
75
+
76
+ response = requests.post(url, json=data)
77
+ print(response.json())</pre>
78
+
79
+ <h3>JavaScript</h3>
80
+ <pre style="background: #f4f4f4; padding: 10px; border-radius: 5px; overflow-x: auto;">
81
+ fetch("https://nipun-ml-deploy-app.hf.space/predict", {
82
+ method: "POST",
83
+ headers: {
84
+ "Content-Type": "application/json"
85
+ },
86
+ body: JSON.stringify({
87
+ sepal_length: 5.1,
88
+ sepal_width: 3.5,
89
+ petal_length: 1.4,
90
+ petal_width: 0.2
91
+ })
92
+ })
93
+ .then(response => response.json())
94
+ .then(data => console.log(data));</pre>
95
+ </div>
96
+
97
  <script>
98
  async function predict() {
99
  const data = {