File size: 1,293 Bytes
5ba3309
0a547e9
 
e41d913
0a547e9
 
e41d913
 
0a547e9
 
5ba3309
8c3c72b
 
 
 
63318d3
8c3c72b
 
 
 
 
 
 
 
 
 
 
 
 
5f32ca7
 
 
 
 
 
 
 
afc9461
5f32ca7
afc9461
5f32ca7
 
 
 
8c3c72b
0a547e9
5ba3309
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
import gradio as gr
from threading import Thread
import time
import anvil.server
from registration import register,get_register,func_reg
from library import get_file,get_files

anvil.server.connect('55MH4EBKM22EP4E6D5T6CVSL-VGO5X4SM6JEXGJVT')
register(get_file)
register(get_files)

# with gr.Blocks() as block:
#     textbox = gr.inputs.Textbox(label='Function Register')
#     button = gr.Button(value="Show Function Calls")
#     button.click(get_register,inputs=None,outputs=[textbox])

# block.launch()
import json
import ast
def my_inference_function(name):
#   print(ast.literal_eval(name)['name'])
  return "Input Data: " + name + ", stay tuned for ML models from this API"

gradio_interface = gr.Interface(
  fn=my_inference_function,
  inputs="text",
  outputs="text",
  title="REST API with Gradio and Huggingface Spaces",
  description='''Inputs should be json of test item e.g., as a dictionary; 
  output right now is just returning the input; later label will be returned.

  This is how to call the API from Python: 

  import requests

  response = requests.post("https://gmshroff-gmserver.hf.space/run/predict", json={
  "data": [
    "\<put some json string here\>",
  ]}).json()

  data = response["data"])

  ''')

gradio_interface.launch()
# anvil.server.wait_forever()