Spaces:
Runtime error
Runtime error
Ramesh-vani
commited on
Commit
•
57193ba
1
Parent(s):
01531ac
Update app.py
Browse files
app.py
CHANGED
@@ -3,30 +3,29 @@ import subprocess
|
|
3 |
|
4 |
def run_command(command):
|
5 |
process = subprocess.Popen(command, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
6 |
-
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
|
14 |
# Example usage
|
15 |
|
16 |
-
|
17 |
def my_inference_function(name):
|
18 |
-
|
19 |
|
20 |
gradio_interface = gradio.Interface(
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
)
|
32 |
gradio_interface.launch()
|
|
|
3 |
|
4 |
def run_command(command):
|
5 |
process = subprocess.Popen(command, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
6 |
+
output, error = process.communicate()
|
7 |
+
if process.returncode == 0:
|
8 |
+
result = output.decode('utf-8')
|
9 |
+
return result
|
10 |
+
else:
|
11 |
+
result = error.decode('utf-8')
|
12 |
+
return result
|
13 |
|
14 |
# Example usage
|
15 |
|
|
|
16 |
def my_inference_function(name):
|
17 |
+
return "Hello " + name + "!"
|
18 |
|
19 |
gradio_interface = gradio.Interface(
|
20 |
+
fn=run_command,
|
21 |
+
inputs="text",
|
22 |
+
outputs="text",
|
23 |
+
examples=[
|
24 |
+
["ls -l"],
|
25 |
+
["pip install bs4"]
|
26 |
+
],
|
27 |
+
title="REST API with Gradio and Huggingface Spaces",
|
28 |
+
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.",
|
29 |
+
article="© Tom Söderlund 2022"
|
30 |
)
|
31 |
gradio_interface.launch()
|