File size: 1,208 Bytes
d74d80d 7f07db8 d74d80d f9f8d44 c7ef637 f9f8d44 c7ef637 7f07db8 d74d80d f9f8d44 d74d80d c7ef637 d74d80d afc9461 d74d80d 5f32ca7 d74d80d 5f32ca7 d74d80d 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 49 50 |
import gradio as gr
from threading import Thread
import time
import anvil.server
import os
anvil.server.connect('55MH4EBKM22EP4E6D5T6CVSL-VGO5X4SM6JEXGJVT')
import json
import ast
def run_script(scriptname):
# return scriptname
os.system(scriptname+' > ./out.txt')
with open('./out.txt','r') as f: output=f.read()
return output
@anvil.server.callable
def run_command(scriptname):
os.system(scriptname+' > ./out.txt')
with open('./out.txt','r') as f: output=f.read()
return output
@anvil.server.callable
def get_file(filename):
m = BlobMedia('text/plain', 'Hello, world!', name='hello.txt')
return m
gradio_interface = gr.Interface(
fn=run_script,
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()
|