Spaces:
Runtime error
Runtime error
Ramesh-vani
commited on
Commit
·
f276882
1
Parent(s):
6667ce7
Update app.py
Browse files
app.py
CHANGED
@@ -1,15 +1,36 @@
|
|
1 |
import gradio
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2 |
|
3 |
def my_inference_function(name):
|
4 |
return "Hello " + name + "!"
|
5 |
|
6 |
gradio_interface = gradio.Interface(
|
7 |
-
fn=
|
8 |
inputs="text",
|
9 |
outputs="text",
|
10 |
examples=[
|
11 |
-
["
|
12 |
-
["
|
13 |
],
|
14 |
title="REST API with Gradio and Huggingface Spaces",
|
15 |
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.",
|
|
|
1 |
import gradio
|
2 |
+
import subprocess
|
3 |
+
|
4 |
+
def run_command(command):
|
5 |
+
try:
|
6 |
+
result = subprocess.run(
|
7 |
+
command,
|
8 |
+
shell=True,
|
9 |
+
check=True,
|
10 |
+
text=True,
|
11 |
+
stdout=subprocess.PIPE,
|
12 |
+
stderr=subprocess.PIPE,
|
13 |
+
input=None # You can provide input to the command here as a string
|
14 |
+
)
|
15 |
+
return result.stdout.strip()
|
16 |
+
except subprocess.CalledProcessError as e:
|
17 |
+
return f"Error: {e}"
|
18 |
+
except Exception as e:
|
19 |
+
return f"An error occurred: {e}"
|
20 |
+
|
21 |
+
# Example usage
|
22 |
+
|
23 |
|
24 |
def my_inference_function(name):
|
25 |
return "Hello " + name + "!"
|
26 |
|
27 |
gradio_interface = gradio.Interface(
|
28 |
+
fn=run_command,
|
29 |
inputs="text",
|
30 |
outputs="text",
|
31 |
examples=[
|
32 |
+
["ls -l"],
|
33 |
+
["pip install bs4"]
|
34 |
],
|
35 |
title="REST API with Gradio and Huggingface Spaces",
|
36 |
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.",
|