dwani 0.1.5__py3-none-any.whl → 0.1.6__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
dwani/__init__.py CHANGED
@@ -3,9 +3,11 @@ from .chat import Chat
3
3
  from .audio import Audio
4
4
  from .vision import Vision
5
5
  from .asr import ASR
6
+ from .translate import Translate
6
7
  from .exceptions import DhwaniAPIError
8
+ from .docs import Documents
7
9
 
8
- __all__ = ["DhwaniClient", "Chat", "Audio", "Vision", "ASR", "DhwaniAPIError"]
10
+ __all__ = ["DhwaniClient", "Chat", "Audio", "Vision", "ASR", "DhwaniAPIError", "Translate", "Documents"]
9
11
 
10
12
  # Optionally, instantiate a default client for convenience
11
13
  api_key = None
@@ -37,3 +39,27 @@ class asr:
37
39
  @staticmethod
38
40
  def transcribe(*args, **kwargs):
39
41
  return _get_client().transcribe(*args, **kwargs)
42
+
43
+
44
+ class translate:
45
+ @staticmethod
46
+ def run_translate(*args, **kwargs):
47
+ return _get_client().translate(*args, **kwargs)
48
+
49
+
50
+ class document:
51
+ @staticmethod
52
+ def run_ocr(*args, **kwargs):
53
+ return _get_client().ocr(*args, **kwargs)
54
+ @staticmethod
55
+ def run_summarize(*args, **kwargs):
56
+ return _get_client().summarize(*args, **kwargs)
57
+ @staticmethod
58
+ def run_extract(*args, **kwargs):
59
+ return _get_client().extract(*args, **kwargs)
60
+ @staticmethod
61
+ def run_doc_query(*args, **kwargs):
62
+ return _get_client().doc_query(*args, **kwargs)
63
+ @staticmethod
64
+ def run_doc_query_kannada(*args, **kwargs):
65
+ return _get_client().doc_query_kannada(*args, **kwargs)
dwani/client.py CHANGED
@@ -12,35 +12,43 @@ class DhwaniClient:
12
12
  def _headers(self):
13
13
  return {"X-API-Key": self.api_key}
14
14
 
15
- def chat(self, prompt, src_lang, tgt_lang, **kwargs):
16
- from .chat import chat_create
17
- return chat_create(self, prompt, src_lang, tgt_lang, **kwargs)
18
-
19
15
  def translate(self, sentences, src_lang, tgt_lang, **kwargs):
20
16
  from .translate import run_translate
21
- return run_translate(self, sentences=sentences,src_lang= src_lang, tgt_lang=tgt_lang, **kwargs)
17
+ return run_translate(self, sentences=sentences, src_lang=src_lang, tgt_lang=tgt_lang, **kwargs)
22
18
 
23
- def speech(self, *args, **kwargs):
19
+ def chat(self, prompt, src_lang, tgt_lang, **kwargs):
20
+ from .chat import chat_create
21
+ return chat_create(self, prompt=prompt, src_lang=src_lang, tgt_lang=tgt_lang, **kwargs)
22
+
23
+ def speech(self, input, response_format="mp3", **kwargs):
24
24
  from .audio import audio_speech
25
- return audio_speech(self, *args, **kwargs)
25
+ return audio_speech(self, input=input, response_format=response_format, **kwargs)
26
26
 
27
- def caption(self, file_path, query="describe the image", src_lang="eng_Latn", tgt_lang="kan_Knda"):
27
+ def caption(self, file_path, query="describe the image", src_lang="eng_Latn", tgt_lang="kan_Knda", **kwargs):
28
28
  from .vision import vision_caption
29
- return vision_caption(self, file_path, query, src_lang, tgt_lang)
29
+ return vision_caption(self, file_path=file_path, query=query, src_lang=src_lang, tgt_lang=tgt_lang, **kwargs)
30
30
 
31
- def transcribe(self, *args, **kwargs):
31
+ def transcribe(self, file_path, language=None, **kwargs):
32
32
  from .asr import asr_transcribe
33
- return asr_transcribe(self, *args, **kwargs)
33
+ return asr_transcribe(self, file_path=file_path, language=language, **kwargs)
34
34
 
35
- def document_ocr(self, file_path, language=None):
35
+ def document_ocr(self, file_path, language=None, **kwargs):
36
36
  from .docs import document_ocr
37
- return document_ocr(self, file_path, language)
38
-
39
- def document_translate(self, file_path, src_lang, tgt_lang):
40
- from .docs import document_translate
41
- return document_translate(self, file_path, src_lang, tgt_lang)
37
+ return document_ocr(self, file_path=file_path, language=language, **kwargs)
42
38
 
43
- def document_summarize(self, file_path, language=None):
39
+ def document_summarize(self, file_path, page_number=1, src_lang="eng_Latn", tgt_lang="kan_Knda", **kwargs):
44
40
  from .docs import document_summarize
45
- return document_summarize(self, file_path, language)
41
+ return document_summarize(self, file_path, page_number, src_lang, tgt_lang, **kwargs)
42
+
43
+ def extract(self, file_path, page_number=1, src_lang="eng_Latn", tgt_lang="kan_Knda", **kwargs):
44
+ from .docs import extract
45
+ return extract(self, file_path=file_path, page_number=page_number, src_lang=src_lang,tgt_lang=tgt_lang, **kwargs)
46
+
47
+
48
+ def doc_query( self, file_path, page_number=1, prompt="list the key points", src_lang="eng_Latn", tgt_lang="kan_Knda" , **kwargs ):
49
+ from .docs import doc_query
50
+ return doc_query( self, file_path, page_number=page_number, prompt=prompt, src_lang=src_lang, tgt_lang=tgt_lang , **kwargs )
46
51
 
52
+ def doc_query_kannada(self, file_path, page_number=1, prompt="list key points", src_lang="eng_Latn", language=None, **kwargs):
53
+ from .docs import doc_query_kannada
54
+ return doc_query_kannada(self, file_path=file_path, page_number=page_number, prompt=prompt, src_lang=src_lang, language=language, **kwargs)
dwani/docs.py CHANGED
@@ -18,17 +18,20 @@ def document_ocr(client, file_path, language=None):
18
18
  raise DhwaniAPIError(resp)
19
19
  return resp.json()
20
20
 
21
- def document_translate(client, file_path, src_lang, tgt_lang):
22
- """Translate a document (image/PDF with text) from src_lang to tgt_lang."""
21
+ def document_summarize(client, file_path, page_number=1, src_lang="eng_Latn", tgt_lang="kan_Knda"):
22
+ """Summarize a PDF document with language and page number options."""
23
+ url = f"{client.api_base}/v1/indic-summarize-pdf"
24
+ headers = client._headers()
23
25
  with open(file_path, "rb") as f:
24
- files = {"file": f}
26
+ files = {"file": (file_path, f, "application/pdf")}
25
27
  data = {
28
+ "page_number": str(page_number),
26
29
  "src_lang": src_lang,
27
30
  "tgt_lang": tgt_lang
28
31
  }
29
32
  resp = requests.post(
30
- f"{client.api_base}/v1/document/translate",
31
- headers=client._headers(),
33
+ url,
34
+ headers=headers,
32
35
  files=files,
33
36
  data=data
34
37
  )
@@ -36,16 +39,83 @@ def document_translate(client, file_path, src_lang, tgt_lang):
36
39
  raise DhwaniAPIError(resp)
37
40
  return resp.json()
38
41
 
39
- def document_summarize(client, file_path, language=None):
40
- """Summarize a document (image/PDF/text)."""
42
+
43
+ def extract(client, file_path, page_number, src_lang, tgt_lang):
44
+ """
45
+ Extract and translate text from a document (image/PDF) using query parameters.
46
+ """
47
+ # Build the URL with query parameters
48
+ url = (
49
+ f"{client.api_base}/v1/indic-extract-text/"
50
+ f"?page_number={page_number}&src_lang={src_lang}&tgt_lang={tgt_lang}"
51
+ )
52
+ headers = client._headers()
53
+ # 'requests' handles multipart/form-data automatically
41
54
  with open(file_path, "rb") as f:
42
- files = {"file": f}
43
- data = {}
55
+ files = {"file": (file_path, f, "application/pdf")}
56
+ resp = requests.post(
57
+ url,
58
+ headers=headers,
59
+ files=files
60
+ )
61
+ if resp.status_code != 200:
62
+ raise DhwaniAPIError(resp)
63
+ return resp.json()
64
+
65
+ def doc_query(
66
+ client,
67
+ file_path,
68
+ page_number=1,
69
+ prompt="list the key points",
70
+ src_lang="eng_Latn",
71
+ tgt_lang="kan_Knda"
72
+ ):
73
+ """Query a document with a custom prompt and language options."""
74
+ url = f"{client.api_base}/v1/indic-custom-prompt-pdf"
75
+ headers = client._headers()
76
+ with open(file_path, "rb") as f:
77
+ files = {"file": (file_path, f, "application/pdf")}
78
+ data = {
79
+ "page_number": str(page_number),
80
+ "prompt": prompt,
81
+ "source_language": src_lang,
82
+ "target_language": tgt_lang
83
+ }
84
+ resp = requests.post(
85
+ url,
86
+ headers=headers,
87
+ files=files,
88
+ data=data
89
+ )
90
+ if resp.status_code != 200:
91
+ raise DhwaniAPIError(resp)
92
+ return resp.json()
93
+
94
+
95
+ def doc_query_kannada(
96
+ client,
97
+ file_path,
98
+ page_number=1,
99
+ prompt="list key points",
100
+ src_lang="eng_Latn",
101
+ language=None
102
+ ):
103
+ """Summarize a document (image/PDF/text) with custom prompt and language."""
104
+ url = f"{client.api_base}/v1/indic-custom-prompt-kannada-pdf"
105
+ headers = client._headers()
106
+ # 'requests' will handle multipart/form-data automatically
107
+ with open(file_path, "rb") as f:
108
+ files = {"file": (file_path, f, "application/pdf")}
109
+ data = {
110
+ "page_number": str(page_number),
111
+ "prompt": prompt,
112
+ "src_lang": src_lang,
113
+ }
44
114
  if language:
45
115
  data["language"] = language
46
116
  resp = requests.post(
47
- f"{client.api_base}/v1/document/summarize",
48
- headers=client._headers(),
117
+ url,
118
+ headers=headers,
49
119
  files=files,
50
120
  data=data
51
121
  )
@@ -53,6 +123,8 @@ def document_summarize(client, file_path, language=None):
53
123
  raise DhwaniAPIError(resp)
54
124
  return resp.json()
55
125
 
126
+
127
+
56
128
  class Documents:
57
129
  @staticmethod
58
130
  def ocr(file_path, language=None):
@@ -60,11 +132,18 @@ class Documents:
60
132
  return _get_client().document_ocr(file_path, language)
61
133
 
62
134
  @staticmethod
63
- def translate(file_path, src_lang, tgt_lang):
135
+ def summarize(*args, **kwargs):
64
136
  from . import _get_client
65
- return _get_client().document_translate(file_path, src_lang, tgt_lang)
66
-
137
+ return _get_client().document_summarize(*args, **kwargs)
138
+ @staticmethod
139
+ def run_extract(*args, **kwargs):
140
+ from . import _get_client
141
+ return _get_client().extract(*args, **kwargs)
142
+ @staticmethod
143
+ def run_doc_query(*args, **kwargs):
144
+ from . import _get_client
145
+ return _get_client().doc_query(*args, **kwargs)
67
146
  @staticmethod
68
- def summarize(file_path, language=None):
147
+ def run_doc_query_kannada(*args, **kwargs):
69
148
  from . import _get_client
70
- return _get_client().document_summarize(file_path, language)
149
+ return _get_client().doc_query_kannada(*args, **kwargs)
dwani/translate.py CHANGED
@@ -20,10 +20,7 @@ def run_translate(client, sentences, src_lang, tgt_lang, **kwargs):
20
20
 
21
21
  class Translate:
22
22
  @staticmethod
23
- def translate(sentence, src_lang, tgt_lang, **kwargs):
23
+ def run_translate(sentences, src_lang, tgt_lang, **kwargs):
24
24
  from . import _get_client
25
- client = _get_client()
26
- # Ensure sentences is always a list
27
- response = run_translate(client, [sentence], src_lang, tgt_lang, **kwargs)
28
- # Return the first translation, or None if not found
29
- return response.get("translations", [None])[0]
25
+ return _get_client().translate(sentences, src_lang, tgt_lang, **kwargs)
26
+
@@ -1,7 +1,7 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: dwani
3
- Version: 0.1.5
4
- Summary: Multimodal API for Indian languages (speech, vision, LLMs, TTS, ASR, etc.)
3
+ Version: 0.1.6
4
+ Summary: Multimodal API for Indian languages (Chat, Vision, TTS, ASR, Translate, Docs)
5
5
  Author-email: sachin <python@dwani.ai>
6
6
  License: MIT License
7
7
 
@@ -59,6 +59,10 @@ dwani.api_base = os.getenv("DWANI_API_BASE_URL")
59
59
  resp = dwani.Chat.create(prompt="Hello!", src_lang="eng_Latn", tgt_lang="kan_Knda")
60
60
  print(resp)
61
61
  ```
62
+ ```json
63
+ {'response': 'ನಮಸ್ತೆ! ಭಾರತ ಮತ್ತು ಕರ್ನಾಟಕವನ್ನು ಗಮನದಲ್ಲಿಟ್ಟುಕೊಂಡು ಇಂದು ನಿಮ್ಮ ಪ್ರಶ್ನೆಗಳಿಗೆ ನಾನು ನಿಮಗೆ ಹೇಗೆ ಸಹಾಯ ಮಾಡಲಿ?'}
64
+ ```
65
+
62
66
 
63
67
  #### Vision Query
64
68
  ```python
@@ -70,13 +74,27 @@ result = dwani.Vision.caption(
70
74
  )
71
75
  print(result)
72
76
  ```
77
+ ```json
78
+ {'answer': 'ಒಂದು ವಾಕ್ಯದಲ್ಲಿ ಚಿತ್ರದ ಸಾರಾಂಶವನ್ನು ಇಲ್ಲಿ ನೀಡಲಾಗಿದೆಃ ಪ್ರಕಟಣೆಯ ಅವಲೋಕನವು ಪ್ರಸ್ತುತ ಅರವತ್ತನಾಲ್ಕು ದೇಶಗಳು/ಪ್ರದೇಶಗಳನ್ನು ಸೇರಿಸಲಾಗಿದೆ ಮತ್ತು ಇನ್ನೂ ಹದಿನಾರು ಪ್ರದೇಶಗಳನ್ನು ಸೇರಿಸಬೇಕಾಗಿದೆ. ಒದಗಿಸಲಾದ ಚಿತ್ರದಲ್ಲಿ ಲಾಂಛನವು ಕಾಣಿಸುವುದಿಲ್ಲ.'}
79
+ ```
73
80
 
74
81
  #### Speech to Text - Automatic Speech Recognition (ASR)
75
82
  ```python
76
83
  result = dwani.ASR.transcribe(file_path="kannada_sample.wav", language="kannada")
77
84
  print(result)
78
85
  ```
86
+ ```json
87
+ {'text': 'ಕರ್ನಾಟಕ ದ ರಾಜಧಾನಿ ಯಾವುದು'}
88
+ ```
79
89
 
90
+ ### Translate
91
+ ```python
92
+ resp = dwani.Translate.run_translate(sentences=["hi"], src_lang="eng_Latn", tgt_lang="kan_Knda")
93
+ print(resp)
94
+ ```
95
+ ```json
96
+ {'translations': ['ಹಾಯ್']}
97
+ ```
80
98
  #### Text to Speech - Speech Synthesis
81
99
 
82
100
  ```python
@@ -85,16 +103,18 @@ with open("output.mp3", "wb") as f:
85
103
  f.write(response)
86
104
  ```
87
105
 
88
-
106
+ #### Document - Extract Text
107
+ ```python
108
+ result = dwani.Documents.run_extract(file_path = "dwani-workshop.pdf", page_number=1, src_lang="eng_Latn",tgt_lang="kan_Knda" )
109
+ print(result)
110
+ ```
111
+ ```json
112
+ {'pages': [{'processed_page': 1, 'page_content': ' a plain text representation of the document', 'translated_content': 'ಡಾಕ್ಯುಮೆಂಟ್ನ ಸರಳ ಪಠ್ಯ ಪ್ರಾತಿನಿಧ್ಯವನ್ನು ಇಲ್ಲಿ ನೀಡಲಾಗಿದೆ, ಅದನ್ನು ಸ್ವಾಭಾವಿಕವಾಗಿ ಓದುವಂತೆಃ'}]}
113
+ ```
89
114
 
90
115
  - Website -> [dwani.ai](https://dwani.ai)
91
116
 
92
117
 
93
-
94
- #### Contact
95
- - For any questions or issues, please open an issue on GitHub or contact us via email.
96
- - For collaborations
97
- - Join the discord group - [invite link](https://discord.gg/WZMCerEZ2P)
98
118
  <!--
99
119
  ## local development
100
120
  pip install -e .
@@ -0,0 +1,14 @@
1
+ dwani/__init__.py,sha256=ldO5OND7DvJlbxaQ0R57Cc73jJTnCSslDDt4I4r-Op8,1895
2
+ dwani/asr.py,sha256=Y5Mbv1KsvhfXNZacMZycUHPn79NRQC-XPH0j9SYPUSY,590
3
+ dwani/audio.py,sha256=Q9vw4uBxGy1vQzmiZjZGrY8hkAEQNkGhjz5OcnpFEQQ,888
4
+ dwani/chat.py,sha256=WFuEShNd4nd6KUbIZTkm3eyPGoP33GepOLJax86nNn8,720
5
+ dwani/client.py,sha256=OrnwqxBQMfEZ1iQEleFigNujiZve3ox53yv5aSmB3iQ,2849
6
+ dwani/docs.py,sha256=s7lgw9tfA0IlItAMlwnPuuxMEmS1ls9ygEIgjuUKlcg,4550
7
+ dwani/exceptions.py,sha256=qEN5ukqlnN7v-kHNEnISWFMpPMt6uTft9mPsTXJ4LVA,227
8
+ dwani/translate.py,sha256=SH8daC0MLudM3GX3ezoWufNmh1u1Ym4LELiUlWHeyeM,791
9
+ dwani/vision.py,sha256=JtMSS0hI-8gxtLugVP10__enZsPPy8jheMyWXvrGrdw,1015
10
+ dwani-0.1.6.dist-info/licenses/LICENSE,sha256=IAD8tbwWZbPWHXgYjabHoMv0aaUzZUYzYiEbfhTCisY,1070
11
+ dwani-0.1.6.dist-info/METADATA,sha256=A3XIToek1Gj1y4rX8Ipd7-6fEa2kShIjUVl6ZD38j4o,4685
12
+ dwani-0.1.6.dist-info/WHEEL,sha256=DnLRTWE75wApRYVsjgc6wsVswC54sMSJhAEd4xhDpBk,91
13
+ dwani-0.1.6.dist-info/top_level.txt,sha256=AM5EhkyuO_EXQFR9JIxEV6tAYMCCyc-a1dLifpCGBUk,6
14
+ dwani-0.1.6.dist-info/RECORD,,
@@ -1,14 +0,0 @@
1
- dwani/__init__.py,sha256=P2pyHkZ7JHn6lHSEbCdV4hjYAwCOXHN3RbsNIU0F5PE,1084
2
- dwani/asr.py,sha256=Y5Mbv1KsvhfXNZacMZycUHPn79NRQC-XPH0j9SYPUSY,590
3
- dwani/audio.py,sha256=Q9vw4uBxGy1vQzmiZjZGrY8hkAEQNkGhjz5OcnpFEQQ,888
4
- dwani/chat.py,sha256=WFuEShNd4nd6KUbIZTkm3eyPGoP33GepOLJax86nNn8,720
5
- dwani/client.py,sha256=saQxRBcERSMoCMOqBIe_IqRygh9-e4KxF3iZZvBEZDc,1826
6
- dwani/docs.py,sha256=2B87KqshPl7-2gDJAJxdvcgmPWuC2IQ1FcsDIyeVJPg,2202
7
- dwani/exceptions.py,sha256=qEN5ukqlnN7v-kHNEnISWFMpPMt6uTft9mPsTXJ4LVA,227
8
- dwani/translate.py,sha256=nYB62DLoPf7Weg26aNtpoEpyasDIsArVTzl5xKPp6eI,972
9
- dwani/vision.py,sha256=JtMSS0hI-8gxtLugVP10__enZsPPy8jheMyWXvrGrdw,1015
10
- dwani-0.1.5.dist-info/licenses/LICENSE,sha256=IAD8tbwWZbPWHXgYjabHoMv0aaUzZUYzYiEbfhTCisY,1070
11
- dwani-0.1.5.dist-info/METADATA,sha256=qxXqLp_wZG_eoGD29p1HdVZFjfpG4ExxJ1xDeyb6O7U,3118
12
- dwani-0.1.5.dist-info/WHEEL,sha256=DnLRTWE75wApRYVsjgc6wsVswC54sMSJhAEd4xhDpBk,91
13
- dwani-0.1.5.dist-info/top_level.txt,sha256=AM5EhkyuO_EXQFR9JIxEV6tAYMCCyc-a1dLifpCGBUk,6
14
- dwani-0.1.5.dist-info/RECORD,,
File without changes