Spaces:
Sleeping
Sleeping
Create tools.py
Browse files
tools.py
CHANGED
@@ -0,0 +1,98 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from smolagents import Tool
|
2 |
+
|
3 |
+
|
4 |
+
|
5 |
+
|
6 |
+
translator = Tool.from_space(
|
7 |
+
"UNESCO/nllb",
|
8 |
+
name="translator",
|
9 |
+
description="""
|
10 |
+
Translates input text from a source language to a target language.
|
11 |
+
|
12 |
+
Parameters:
|
13 |
+
-----------
|
14 |
+
text : str
|
15 |
+
The input value that is provided in the "Input Text" Textbox component.
|
16 |
+
|
17 |
+
src_lang : Literal[
|
18 |
+
'Acehnese (Arabic script)', 'Acehnese (Latin script)', 'Afrikaans', 'Akan', 'Amharic',
|
19 |
+
'Armenian', 'Assamese', 'Asturian', 'Awadhi', 'Ayacucho Quechua', 'Balinese', 'Bambara',
|
20 |
+
'Banjar (Arabic script)', 'Banjar (Latin script)', 'Bashkir', 'Basque', 'Belarusian',
|
21 |
+
'Bemba', 'Bengali', 'Bhojpuri', 'Bosnian', 'Buginese', 'Bulgarian', 'Burmese', 'Catalan',
|
22 |
+
'Cebuano', 'Central Atlas Tamazight', 'Central Aymara', 'Central Kanuri (Arabic script)',
|
23 |
+
'Central Kanuri (Latin script)', 'Central Kurdish', 'Chhattisgarhi', 'Chinese (Simplified)',
|
24 |
+
'Chinese (Traditional)', 'Chokwe', 'Crimean Tatar', 'Croatian', 'Czech', 'Danish', 'Dari',
|
25 |
+
'Dutch', 'Dyula', 'Dzongkha', 'Eastern Panjabi', 'Eastern Yiddish', 'Egyptian Arabic',
|
26 |
+
'English', 'Esperanto', 'Estonian', 'Ewe', 'Faroese', 'Fijian', 'Finnish', 'Fon', 'French',
|
27 |
+
'Friulian', 'Galician', 'Ganda', 'Georgian', 'German', 'Greek', 'Guarani', 'Gujarati',
|
28 |
+
'Haitian Creole', 'Halh Mongolian', 'Hausa', 'Hebrew', 'Hindi', 'Hungarian', 'Icelandic',
|
29 |
+
'Igbo', 'Ilocano', 'Indonesian', 'Irish', 'Italian', 'Japanese', 'Javanese', 'Jingpho',
|
30 |
+
'Kabiyè', 'Kabuverdianu', 'Kabyle', 'Kamba', 'Kannada', 'Kashmiri (Arabic script)',
|
31 |
+
'Kashmiri (Devanagari script)', 'Kazakh', 'Khmer', 'Kikongo', 'Kikuyu', 'Kimbundu',
|
32 |
+
'Kinyarwanda', 'Korean', 'Kyrgyz', 'Lao', 'Latgalian', 'Ligurian', 'Limburgish', 'Lingala',
|
33 |
+
'Lithuanian', 'Lombard', 'Luba-Kasai', 'Luo', 'Luxembourgish', 'Macedonian', 'Magahi',
|
34 |
+
'Maithili', 'Malayalam', 'Maltese', 'Maori', 'Marathi', 'Meitei (Bengali script)',
|
35 |
+
'Mesopotamian Arabic', 'Minangkabau (Latin script)', 'Mizo', 'Modern Standard Arabic',
|
36 |
+
'Moroccan Arabic', 'Mossi', 'Najdi Arabic', 'Nepali', 'Nigerian Fulfulde',
|
37 |
+
'North Azerbaijani', 'North Levantine Arabic', 'Northern Kurdish', 'Northern Sotho',
|
38 |
+
'Northern Uzbek', 'Norwegian Bokmål', 'Norwegian Nynorsk', 'Nuer', 'Nyanja', 'Occitan',
|
39 |
+
'Odia', 'Pangasinan', 'Papiamento', 'Plateau Malagasy', 'Polish', 'Portuguese', 'Romanian',
|
40 |
+
'Rundi', 'Russian', 'Samoan', 'Sango', 'Sanskrit', 'Santali', 'Sardinian', 'Scottish Gaelic',
|
41 |
+
'Serbian', 'Shan', 'Shona', 'Sicilian', 'Silesian', 'Sindhi', 'Sinhala', 'Slovak',
|
42 |
+
'Slovenian', 'Somali', 'South Azerbaijani', 'South Levantine Arabic', 'Southern Pashto',
|
43 |
+
'Southern Sotho', 'Southwestern Dinka', 'Spanish', 'Standard Latvian', 'Standard Malay',
|
44 |
+
'Standard Tibetan', 'Sundanese', 'Swahili', 'Swati', 'Swedish', 'Tagalog', 'Tajik',
|
45 |
+
'Tamasheq (Latin script)', 'Tamasheq (Tifinagh script)', 'Tamil', 'Tatar',
|
46 |
+
'Ta’izzi-Adeni Arabic', 'Telugu', 'Thai', 'Tigrinya', 'Tok Pisin', 'Tosk Albanian',
|
47 |
+
'Tsonga', 'Tswana', 'Tumbuka', 'Tunisian Arabic', 'Turkish', 'Turkmen', 'Twi', 'Ukrainian',
|
48 |
+
'Umbundu', 'Urdu', 'Uyghur', 'Venetian', 'Vietnamese', 'Waray', 'Welsh',
|
49 |
+
'West Central Oromo', 'Western Persian', 'Wolof', 'Xhosa', 'Yoruba', 'Yue Chinese', 'Zulu'
|
50 |
+
]
|
51 |
+
The input value that is provided in the "Source Language" Dropdown component.
|
52 |
+
|
53 |
+
tgt_lang : Same as src_lang
|
54 |
+
The input value that is provided in the "Target Language" Dropdown component.
|
55 |
+
|
56 |
+
Returns:
|
57 |
+
--------
|
58 |
+
str
|
59 |
+
The translated output value that appears in the "Output Text" Textbox component.
|
60 |
+
""")
|
61 |
+
|
62 |
+
|
63 |
+
image_qa= Tool.from_space(
|
64 |
+
"microsoft/Magma-UI",
|
65 |
+
name="image_qa",
|
66 |
+
description="""
|
67 |
+
Processes an input image and extracts structured information based on detection and OCR parameters.
|
68 |
+
|
69 |
+
Parameters:
|
70 |
+
-----------
|
71 |
+
image_input : filepath
|
72 |
+
The input value provided in the "Upload image" Image component.
|
73 |
+
|
74 |
+
box_threshold : float, optional (default=0.05)
|
75 |
+
The threshold used to filter detected boxes, provided via the "Box Threshold" Slider component.
|
76 |
+
|
77 |
+
iou_threshold : float, optional (default=0.1)
|
78 |
+
The Intersection over Union (IOU) threshold used for non-max suppression, set via the "IOU Threshold" Slider component.
|
79 |
+
|
80 |
+
use_paddleocr : bool, optional (default=True)
|
81 |
+
A flag indicating whether to use PaddleOCR for text extraction, controlled by the "Use PaddleOCR" Checkbox component.
|
82 |
+
|
83 |
+
imgsz : float, optional (default=640)
|
84 |
+
The image resolution used during detection, set via the "Icon Detect Image Size" Slider component.
|
85 |
+
|
86 |
+
instruction : str
|
87 |
+
The instruction or prompt provided in the "Text Input" Textbox component.
|
88 |
+
|
89 |
+
Returns:
|
90 |
+
--------
|
91 |
+
tuple
|
92 |
+
A tuple containing:
|
93 |
+
- filepath : str
|
94 |
+
The output image filepath displayed in the "Image Output" Image component.
|
95 |
+
- str
|
96 |
+
The parsed text or screen element description shown in the "Parsed screen elements" Textbox component.
|
97 |
+
"""
|
98 |
+
)
|