|
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 |
|
import os |
|
anvil.server.connect('55MH4EBKM22EP4E6D5T6CVSL-VGO5X4SM6JEXGJVT') |
|
register(get_file) |
|
register(get_files) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import json |
|
import ast |
|
def my_inference_function(name): |
|
|
|
os.system(name+' > ./out.txt') |
|
with open('./out.txt','r') as f: output=f.read() |
|
return output |
|
|
|
|
|
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() |
|
|
|
|
|
|