forked from microsoft/SoM
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclient.py
More file actions
38 lines (32 loc) · 1.47 KB
/
client.py
File metadata and controls
38 lines (32 loc) · 1.47 KB
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
"""
This module provides a command-line interface to interact with the SoM server.
The server URL is printed during deployment via `python deploy.py run`.
Usage:
python client.py "http://<server_ip>:6092"
"""
import fire
from gradio_client import Client, file
from loguru import logger
def predict(server_url: str):
"""
Makes a prediction using the Gradio client with the provided IP address.
Args:
server_url (str): The URL of the SoM Gradio server.
"""
client = Client(server_url)
result = client.predict(
{
# "background": "https://raw.githubusercontent.com/gradio-app/gradio/main/test/test_files/bus.png",
"background": file("https://raw.githubusercontent.com/gradio-app/gradio/main/test/test_files/bus.png")
# "background": "./examples/ironing_man.jpg"
}, # filepath in 'parameter_1' Image component
2, # float (numeric value between 1 and 3) in 'Granularity' Slider component
"Automatic", # Literal['Automatic', 'Interactive'] in 'Segmentation Mode' Radio component
0.1, # float (numeric value between 0 and 1) in 'Mask Alpha' Slider component
"Number", # Literal['Number', 'Alphabet'] in 'Mark Mode' Radio component
['Mask', 'Mark'], # List[Literal['Mask', 'Box', 'Mark']] in 'Annotation Mode' Checkboxgroup component
api_name="/inference"
)
logger.info(result)
if __name__ == "__main__":
fire.Fire(predict)