translate
- class arcgis.ai.translate(text: str | list[str], to_language: list[str], from_language: str | None = 'en', *, gis: GIS | None = None)
Translates language strings passed to the desired array of output cultures.
Parameter
Description
text
list[str] or str. The text to translate.
to_language
Required list of strings. The list of languages to convert to. To see a list of supported languages, use the languages property of the GIS object.
Example: to_language = [“fr”, “de”] (to translate to French and German)
from_language
Optional str. The source language. The default is US English. To see a list of supported languages, use the languages property of the GIS object.
Example: from_language = “en” (for English)
gis
Optional GIS. The connection to the organization that has AI assistants enabled.
- Returns:
arcgis.ai.AIUtilsResponsewith the translations in the results property.
- ..code-block:: python
# Example usage of translate function from arcgis.gis import GIS from arcgis.ai import translate
# Connect to GIS (ensure you have the correct organization set up with AI assistants enabled) gis = GIS(profile=”your_profile”)
# Translate a single string to French and German response = translate(
text=”Hello, how are you?”, to_language=[“fr”, “de”], from_language=”en”,
)
print(response)
analyze_text
- class arcgis.ai.analyze_text(text: str, prompt: str | list[str] | list[dict[str, str]], to_language: str | None = None, from_language: str | None = None, *, gis: GIS | None = None)
Analyzes the provided text against the given prompt(s) using AI capabilities. Allows users to submit text for analysis, which can include tasks such as sentiment analysis, entity recognition, and other natural language processing operations.
Parameter
Description
text
Required string. The text to analyze.
prompt
Required str, list[str], or dict[str, str]. Defines the types of analysis to perform. If a string or list of strings, these are the prompts or instructions. If a dictionary, keys are labels for each analysis type and values are the corresponding prompts/instructions.
Example 1 (string): prompt = “Summarize the following text.”
Example 2 (list): prompt = [
“Summarize the following text.”, “Extract key entities from the following text.”
]
Example 3 (dictionary): prompt = [{
“key”: “summarize_prompt”, “context”: “Summarize the following text.”
}, {
“key”: “entities_prompt”, “context”: “Extract key entities from the following text.”
}]
to_language
Optional string. The output language for analysis. Default is “en”. To see a list of supported languages, use the languages property of the GIS object. (Example: gis.languages)
from_language
Optional string. The source language of the input text. Default is “en”. To see a list of supported languages, use the languages property of the GIS object. (Example: gis.languages)
gis
Optional GIS. The connection to the organization that has AI assistants enabled.
- Returns:
arcgis.ai.AIUtilsResponse|arcgis.ai.AIUtilsExceptionwith the analysis results.
- ..code-block:: python
# Example usage of analyze_text function from arcgis.gis import GIS from arcgis.ai import analyze_text
# Connect to GIS (ensure you have the correct organization set up with AI assistants enabled) gis = GIS(profile=”your_profile”)
# Analyze text with a single prompt response = analyze_text(
text=”ArcGIS is a powerful geographic information system.”, prompt=”What are the key entities in this text?”, to_language=”en”, from_language=”en”,
) print(response)
analyze_image
- class arcgis.ai.analyze_image(image: str, prompt: str | list[str] | list[dict[str, str]], to_language: str | None = None, from_language: str | None = 'en', *, gis: GIS | None = None)
Analyze the image using AI-powered models for object detection, text extraction, image description, and segmentation.
Note
The image must be hosted on an arcgis.com domain. Images from other domains will not be accepted. Currently supported formats: JPEG, PNG
Parameter
Description
image
Required string. URL of the image (must be hosted on arcgis.com domain). Can also be a Base64 encoded string of the image data, but this is not recommended for large images.
prompt
Required str or list[str] or list[dict[str, str]]. Prompt or list of prompts describing the analysis to perform.
Examples: - Single string prompt: “List all the colors present in the image.” - List of string prompts: [“Describe the scene in the image.”, “Identify any text in the image.”] - List of dict prompts: [{“key”: “colors_prompt”, “context”: “List all the colors present in the image.”}, {“key”: “text_prompt”, “context”: “Identify any text in the image.”}]
to_language
Optional str. The target language for translation. If not specified, the default is US English (“en”). To see a list of supported languages, use the languages property of the GIS object.
from_language
Optional str. The source language. The default is US English (“en”).
gis
Optional GIS. The connection to the organization that has AI assistants enabled.
- Returns:
arcgis.ai.AIUtilsResponseorarcgis.ai.AIUtilsExceptionwith the analysis results.
AIUtilsResponse
- pydantic model arcgis.ai.AIUtilsResponse
Response model for AI utilities. This is common response structure for AI utility services like image analysis and text analysis.
- field meta: AIUtilsResponseMetaData | dict | list | str | None = None
The metadata returned from the AI utility service.
- field results: list[AnalyzeResult | TranslateResult | dict] | None = None
The results returned from the AI utility service. Results format varies based on service.
AIUtilsException
AIUtilsResponseMetaData
AnalyzeResult
- pydantic model arcgis.ai.AnalyzeResult
Model for the results returned from the analyze_image function. The structure of the results can vary based on the prompts used and the analysis performed. This is a flexible model that allows for any additional fields returned in the results.
TranslateResult
- pydantic model arcgis.ai.TranslateResult
Model for the results returned from the translate function. The structure of the results can vary based on the prompts used and the analysis performed. This is a flexible model that allows for any additional fields returned in the results.