|
import gradio |
|
import subprocess |
|
|
|
def run_command(command): |
|
process = subprocess.Popen(command, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE) |
|
output, error = process.communicate() |
|
if process.returncode == 0: |
|
result = output.decode('utf-8') |
|
return result |
|
else: |
|
result = error.decode('utf-8') |
|
return result |
|
|
|
|
|
|
|
def my_inference_function(name): |
|
return "Hello " + name + "!" |
|
|
|
gradio_interface = gradio.Interface( |
|
fn=run_command, |
|
inputs="text", |
|
outputs="text", |
|
examples=[ |
|
["ls -l"], |
|
["pip install bs4"] |
|
], |
|
title="REST API with Gradio and Huggingface Spaces", |
|
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.", |
|
article="© Tom Söderlund 2022" |
|
) |
|
gradio_interface.launch() |
|
|