ai: API: Across platform support.
Browse files
API.md
CHANGED
@@ -1,41 +1,121 @@
|
|
1 |
#### Installation
|
2 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
3 |
```
|
4 |
-
pip show gradio_client > /dev/null 2>&1
|
5 |
|
6 |
-
|
7 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
8 |
else
|
9 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
10 |
fi
|
11 |
```
|
12 |
|
13 |
-
####
|
14 |
|
15 |
-
```
|
16 |
-
nano jarvis
|
17 |
-
```
|
18 |
|
|
|
19 |
```
|
|
|
|
|
20 |
#!/usr/bin/env python3
|
|
|
21 |
from gradio_client import Client
|
22 |
-
|
|
|
|
|
23 |
jarvis = Client("hadadrjt/ai")
|
|
|
|
|
|
|
|
|
|
|
|
|
24 |
|
25 |
-
|
26 |
-
|
|
|
|
|
27 |
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
responses = result[0][0][1]
|
33 |
-
print(responses)
|
34 |
```
|
35 |
|
36 |
-
####
|
37 |
|
|
|
|
|
|
|
38 |
```
|
39 |
-
|
40 |
-
|
|
|
41 |
```
|
|
|
1 |
#### Installation
|
2 |
|
3 |
+
```bash
|
4 |
+
#!/bin/bash
|
5 |
+
# Linux/Android (Termux)/MacOS/Windows
|
6 |
+
install_python() {
|
7 |
+
if ! command -v python3 &>/dev/null; then
|
8 |
+
if [[ "$OSTYPE" == "linux-gnu"* ]]; then
|
9 |
+
apt update
|
10 |
+
apt install python3 python3-pip -q -y
|
11 |
+
|
12 |
+
elif [[ "$OSTYPE" == "darwin"* ]]; then
|
13 |
+
if ! command -v brew &>/dev/null; then
|
14 |
+
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
|
15 |
+
fi
|
16 |
+
brew install python
|
17 |
+
|
18 |
+
elif [[ "$OSTYPE" == "cygwin" ]]; then
|
19 |
+
echo "Using Cygwin, please install Python manually."
|
20 |
+
|
21 |
+
elif [[ "$OSTYPE" == "msys" ]]; then
|
22 |
+
echo "Windows detected. Please install Python from python.org or using the Windows Store."
|
23 |
+
exit 1
|
24 |
+
|
25 |
+
fi
|
26 |
+
else
|
27 |
+
echo "Python 3 already installed!"
|
28 |
+
fi
|
29 |
+
}
|
30 |
+
|
31 |
+
install_pip() {
|
32 |
+
if ! command -v pip3 &>/dev/null; then
|
33 |
+
if [[ "$OSTYPE" == "linux-gnu"* || "$OSTYPE" == "darwin"* ]]; then
|
34 |
+
curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py
|
35 |
+
python3 get-pip.py
|
36 |
+
rm get-pip.py
|
37 |
+
elif [[ "$OSTYPE" == "msys"* ]]; then
|
38 |
+
echo "Please make sure pip is installed on Windows. Install pip manually if needed."
|
39 |
+
fi
|
40 |
+
else
|
41 |
+
echo "pip already installed!"
|
42 |
+
fi
|
43 |
+
}
|
44 |
+
|
45 |
+
install_libraries() {
|
46 |
+
pip3 install gradio_client rich --upgrade
|
47 |
+
}
|
48 |
+
|
49 |
+
install_python
|
50 |
+
install_pip
|
51 |
+
install_libraries
|
52 |
+
|
53 |
+
echo "Installation complete! Python, pip, and required packages are installed."
|
54 |
```
|
|
|
55 |
|
56 |
+
```bash
|
57 |
+
#!/bin/bash
|
58 |
+
|
59 |
+
COMMAND="pip"
|
60 |
+
|
61 |
+
if command -v python3 > /dev/null 2>&1; then
|
62 |
+
COMMAND="python3 -m pip"
|
63 |
+
elif command -v python > /dev/null 2>&1; then
|
64 |
+
COMMAND="python -m pip"
|
65 |
+
elif command -v py > /dev/null 2>&1; then
|
66 |
+
COMMAND="py -m pip"
|
67 |
else
|
68 |
+
exit 1
|
69 |
+
fi
|
70 |
+
|
71 |
+
if ! $COMMAND show gradio_client > /dev/null 2>&1 || ! $COMMAND show rich > /dev/null 2>&1; then
|
72 |
+
$COMMAND install gradio_client rich
|
73 |
+
else
|
74 |
+
$COMMAND install gradio_client rich --upgrade
|
75 |
fi
|
76 |
```
|
77 |
|
78 |
+
#### Create JARVIS script.
|
79 |
|
80 |
+
```bash
|
81 |
+
nano jarvis
|
|
|
82 |
|
83 |
+
# If windows user create file manually.
|
84 |
```
|
85 |
+
|
86 |
+
```python
|
87 |
#!/usr/bin/env python3
|
88 |
+
import sys
|
89 |
from gradio_client import Client
|
90 |
+
from rich.console import Console
|
91 |
+
from rich.markdown import Markdown
|
92 |
+
console = Console()
|
93 |
jarvis = Client("hadadrjt/ai")
|
94 |
+
input = " ".join(sys.argv[1:]) if len(sys.argv) > 1 else "Hi!"
|
95 |
+
result = jarvis.predict(multi_input={"text": input}, api_name="/api")
|
96 |
+
responses = result[0][0][1]
|
97 |
+
markdown = Markdown(responses)
|
98 |
+
console.print(markdown)
|
99 |
+
```
|
100 |
|
101 |
+
```bash
|
102 |
+
chmod a+x jarvis
|
103 |
+
# Windows users set permissions to 755 according with linux.
|
104 |
+
```
|
105 |
|
106 |
+
### Run
|
107 |
+
|
108 |
+
```bash
|
109 |
+
./jarvis "Your message here."
|
|
|
|
|
110 |
```
|
111 |
|
112 |
+
#### Linux User's
|
113 |
|
114 |
+
```bash
|
115 |
+
# Bonus for more flexible.
|
116 |
+
sudo mv jarvis /bin/ai
|
117 |
```
|
118 |
+
|
119 |
+
```bash
|
120 |
+
ai "Your message here."
|
121 |
```
|