dwani 0.1.5__tar.gz → 0.1.6__tar.gz
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-0.1.5 → dwani-0.1.6}/PKG-INFO +28 -8
- dwani-0.1.6/README.md +93 -0
- {dwani-0.1.5 → dwani-0.1.6}/dwani/__init__.py +27 -1
- dwani-0.1.6/dwani/client.py +54 -0
- dwani-0.1.6/dwani/docs.py +149 -0
- {dwani-0.1.5 → dwani-0.1.6}/dwani/translate.py +3 -6
- {dwani-0.1.5 → dwani-0.1.6}/dwani.egg-info/PKG-INFO +28 -8
- {dwani-0.1.5 → dwani-0.1.6}/pyproject.toml +2 -2
- dwani-0.1.5/README.md +0 -73
- dwani-0.1.5/dwani/client.py +0 -46
- dwani-0.1.5/dwani/docs.py +0 -70
- {dwani-0.1.5 → dwani-0.1.6}/LICENSE +0 -0
- {dwani-0.1.5 → dwani-0.1.6}/dwani/asr.py +0 -0
- {dwani-0.1.5 → dwani-0.1.6}/dwani/audio.py +0 -0
- {dwani-0.1.5 → dwani-0.1.6}/dwani/chat.py +0 -0
- {dwani-0.1.5 → dwani-0.1.6}/dwani/exceptions.py +0 -0
- {dwani-0.1.5 → dwani-0.1.6}/dwani/vision.py +0 -0
- {dwani-0.1.5 → dwani-0.1.6}/dwani.egg-info/SOURCES.txt +0 -0
- {dwani-0.1.5 → dwani-0.1.6}/dwani.egg-info/dependency_links.txt +0 -0
- {dwani-0.1.5 → dwani-0.1.6}/dwani.egg-info/requires.txt +0 -0
- {dwani-0.1.5 → dwani-0.1.6}/dwani.egg-info/top_level.txt +0 -0
- {dwani-0.1.5 → dwani-0.1.6}/setup.cfg +0 -0
@@ -1,7 +1,7 @@
|
|
1
1
|
Metadata-Version: 2.4
|
2
2
|
Name: dwani
|
3
|
-
Version: 0.1.
|
4
|
-
Summary: Multimodal API for Indian languages (
|
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 .
|
dwani-0.1.6/README.md
ADDED
@@ -0,0 +1,93 @@
|
|
1
|
+
# dwani.ai - python library
|
2
|
+
|
3
|
+
|
4
|
+
### Install the library
|
5
|
+
```bash
|
6
|
+
pip install dwani
|
7
|
+
```
|
8
|
+
|
9
|
+
### Setup the credentials
|
10
|
+
```python
|
11
|
+
import dwani
|
12
|
+
import os
|
13
|
+
|
14
|
+
dwani.api_key = os.getenv("DWANI_API_KEY")
|
15
|
+
|
16
|
+
dwani.api_base = os.getenv("DWANI_API_BASE_URL")
|
17
|
+
```
|
18
|
+
|
19
|
+
### Examples
|
20
|
+
|
21
|
+
#### Text Query
|
22
|
+
```python
|
23
|
+
resp = dwani.Chat.create(prompt="Hello!", src_lang="eng_Latn", tgt_lang="kan_Knda")
|
24
|
+
print(resp)
|
25
|
+
```
|
26
|
+
```json
|
27
|
+
{'response': 'ನಮಸ್ತೆ! ಭಾರತ ಮತ್ತು ಕರ್ನಾಟಕವನ್ನು ಗಮನದಲ್ಲಿಟ್ಟುಕೊಂಡು ಇಂದು ನಿಮ್ಮ ಪ್ರಶ್ನೆಗಳಿಗೆ ನಾನು ನಿಮಗೆ ಹೇಗೆ ಸಹಾಯ ಮಾಡಲಿ?'}
|
28
|
+
```
|
29
|
+
|
30
|
+
|
31
|
+
#### Vision Query
|
32
|
+
```python
|
33
|
+
result = dwani.Vision.caption(
|
34
|
+
file_path="image.png",
|
35
|
+
query="Describe this logo",
|
36
|
+
src_lang="eng_Latn",
|
37
|
+
tgt_lang="kan_Knda"
|
38
|
+
)
|
39
|
+
print(result)
|
40
|
+
```
|
41
|
+
```json
|
42
|
+
{'answer': 'ಒಂದು ವಾಕ್ಯದಲ್ಲಿ ಚಿತ್ರದ ಸಾರಾಂಶವನ್ನು ಇಲ್ಲಿ ನೀಡಲಾಗಿದೆಃ ಪ್ರಕಟಣೆಯ ಅವಲೋಕನವು ಪ್ರಸ್ತುತ ಅರವತ್ತನಾಲ್ಕು ದೇಶಗಳು/ಪ್ರದೇಶಗಳನ್ನು ಸೇರಿಸಲಾಗಿದೆ ಮತ್ತು ಇನ್ನೂ ಹದಿನಾರು ಪ್ರದೇಶಗಳನ್ನು ಸೇರಿಸಬೇಕಾಗಿದೆ. ಒದಗಿಸಲಾದ ಚಿತ್ರದಲ್ಲಿ ಲಾಂಛನವು ಕಾಣಿಸುವುದಿಲ್ಲ.'}
|
43
|
+
```
|
44
|
+
|
45
|
+
#### Speech to Text - Automatic Speech Recognition (ASR)
|
46
|
+
```python
|
47
|
+
result = dwani.ASR.transcribe(file_path="kannada_sample.wav", language="kannada")
|
48
|
+
print(result)
|
49
|
+
```
|
50
|
+
```json
|
51
|
+
{'text': 'ಕರ್ನಾಟಕ ದ ರಾಜಧಾನಿ ಯಾವುದು'}
|
52
|
+
```
|
53
|
+
|
54
|
+
### Translate
|
55
|
+
```python
|
56
|
+
resp = dwani.Translate.run_translate(sentences=["hi"], src_lang="eng_Latn", tgt_lang="kan_Knda")
|
57
|
+
print(resp)
|
58
|
+
```
|
59
|
+
```json
|
60
|
+
{'translations': ['ಹಾಯ್']}
|
61
|
+
```
|
62
|
+
#### Text to Speech - Speech Synthesis
|
63
|
+
|
64
|
+
```python
|
65
|
+
response = dwani.Audio.speech(input="ಕರ್ನಾಟಕ ದ ರಾಜಧಾನಿ ಯಾವುದು", response_format="mp3")
|
66
|
+
with open("output.mp3", "wb") as f:
|
67
|
+
f.write(response)
|
68
|
+
```
|
69
|
+
|
70
|
+
#### Document - Extract Text
|
71
|
+
```python
|
72
|
+
result = dwani.Documents.run_extract(file_path = "dwani-workshop.pdf", page_number=1, src_lang="eng_Latn",tgt_lang="kan_Knda" )
|
73
|
+
print(result)
|
74
|
+
```
|
75
|
+
```json
|
76
|
+
{'pages': [{'processed_page': 1, 'page_content': ' a plain text representation of the document', 'translated_content': 'ಡಾಕ್ಯುಮೆಂಟ್ನ ಸರಳ ಪಠ್ಯ ಪ್ರಾತಿನಿಧ್ಯವನ್ನು ಇಲ್ಲಿ ನೀಡಲಾಗಿದೆ, ಅದನ್ನು ಸ್ವಾಭಾವಿಕವಾಗಿ ಓದುವಂತೆಃ'}]}
|
77
|
+
```
|
78
|
+
|
79
|
+
- Website -> [dwani.ai](https://dwani.ai)
|
80
|
+
|
81
|
+
|
82
|
+
<!--
|
83
|
+
## local development
|
84
|
+
pip install -e .
|
85
|
+
|
86
|
+
|
87
|
+
pip install twine build
|
88
|
+
rm -rf dist/
|
89
|
+
python -m build
|
90
|
+
|
91
|
+
python -m twine upload dist/*
|
92
|
+
|
93
|
+
-->
|
@@ -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)
|
@@ -0,0 +1,54 @@
|
|
1
|
+
import os
|
2
|
+
import requests
|
3
|
+
from .exceptions import DhwaniAPIError
|
4
|
+
|
5
|
+
class DhwaniClient:
|
6
|
+
def __init__(self, api_key=None, api_base=None):
|
7
|
+
self.api_key = api_key or os.getenv("DWANI_API_KEY")
|
8
|
+
self.api_base = api_base or os.getenv("DWANI_API_BASE_URL", "http://localhost:8000")
|
9
|
+
if not self.api_key:
|
10
|
+
raise ValueError("DHWANI_API_KEY not set")
|
11
|
+
|
12
|
+
def _headers(self):
|
13
|
+
return {"X-API-Key": self.api_key}
|
14
|
+
|
15
|
+
def translate(self, sentences, src_lang, tgt_lang, **kwargs):
|
16
|
+
from .translate import run_translate
|
17
|
+
return run_translate(self, sentences=sentences, src_lang=src_lang, tgt_lang=tgt_lang, **kwargs)
|
18
|
+
|
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
|
+
from .audio import audio_speech
|
25
|
+
return audio_speech(self, input=input, response_format=response_format, **kwargs)
|
26
|
+
|
27
|
+
def caption(self, file_path, query="describe the image", src_lang="eng_Latn", tgt_lang="kan_Knda", **kwargs):
|
28
|
+
from .vision import vision_caption
|
29
|
+
return vision_caption(self, file_path=file_path, query=query, src_lang=src_lang, tgt_lang=tgt_lang, **kwargs)
|
30
|
+
|
31
|
+
def transcribe(self, file_path, language=None, **kwargs):
|
32
|
+
from .asr import asr_transcribe
|
33
|
+
return asr_transcribe(self, file_path=file_path, language=language, **kwargs)
|
34
|
+
|
35
|
+
def document_ocr(self, file_path, language=None, **kwargs):
|
36
|
+
from .docs import document_ocr
|
37
|
+
return document_ocr(self, file_path=file_path, language=language, **kwargs)
|
38
|
+
|
39
|
+
def document_summarize(self, file_path, page_number=1, src_lang="eng_Latn", tgt_lang="kan_Knda", **kwargs):
|
40
|
+
from .docs import document_summarize
|
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 )
|
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)
|
@@ -0,0 +1,149 @@
|
|
1
|
+
import requests
|
2
|
+
from .exceptions import DhwaniAPIError
|
3
|
+
|
4
|
+
def document_ocr(client, file_path, language=None):
|
5
|
+
"""OCR a document (image/PDF) and return extracted text."""
|
6
|
+
with open(file_path, "rb") as f:
|
7
|
+
files = {"file": f}
|
8
|
+
data = {}
|
9
|
+
if language:
|
10
|
+
data["language"] = language
|
11
|
+
resp = requests.post(
|
12
|
+
f"{client.api_base}/v1/document/ocr",
|
13
|
+
headers=client._headers(),
|
14
|
+
files=files,
|
15
|
+
data=data
|
16
|
+
)
|
17
|
+
if resp.status_code != 200:
|
18
|
+
raise DhwaniAPIError(resp)
|
19
|
+
return resp.json()
|
20
|
+
|
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()
|
25
|
+
with open(file_path, "rb") as f:
|
26
|
+
files = {"file": (file_path, f, "application/pdf")}
|
27
|
+
data = {
|
28
|
+
"page_number": str(page_number),
|
29
|
+
"src_lang": src_lang,
|
30
|
+
"tgt_lang": tgt_lang
|
31
|
+
}
|
32
|
+
resp = requests.post(
|
33
|
+
url,
|
34
|
+
headers=headers,
|
35
|
+
files=files,
|
36
|
+
data=data
|
37
|
+
)
|
38
|
+
if resp.status_code != 200:
|
39
|
+
raise DhwaniAPIError(resp)
|
40
|
+
return resp.json()
|
41
|
+
|
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
|
54
|
+
with open(file_path, "rb") as f:
|
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
|
+
}
|
114
|
+
if language:
|
115
|
+
data["language"] = language
|
116
|
+
resp = requests.post(
|
117
|
+
url,
|
118
|
+
headers=headers,
|
119
|
+
files=files,
|
120
|
+
data=data
|
121
|
+
)
|
122
|
+
if resp.status_code != 200:
|
123
|
+
raise DhwaniAPIError(resp)
|
124
|
+
return resp.json()
|
125
|
+
|
126
|
+
|
127
|
+
|
128
|
+
class Documents:
|
129
|
+
@staticmethod
|
130
|
+
def ocr(file_path, language=None):
|
131
|
+
from . import _get_client
|
132
|
+
return _get_client().document_ocr(file_path, language)
|
133
|
+
|
134
|
+
@staticmethod
|
135
|
+
def summarize(*args, **kwargs):
|
136
|
+
from . import _get_client
|
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)
|
146
|
+
@staticmethod
|
147
|
+
def run_doc_query_kannada(*args, **kwargs):
|
148
|
+
from . import _get_client
|
149
|
+
return _get_client().doc_query_kannada(*args, **kwargs)
|
@@ -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
|
23
|
+
def run_translate(sentences, src_lang, tgt_lang, **kwargs):
|
24
24
|
from . import _get_client
|
25
|
-
|
26
|
-
|
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.
|
4
|
-
Summary: Multimodal API for Indian languages (
|
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 .
|
@@ -4,8 +4,8 @@ build-backend = "setuptools.build_meta"
|
|
4
4
|
|
5
5
|
[project]
|
6
6
|
name = "dwani"
|
7
|
-
version = "0.1.
|
8
|
-
description = "Multimodal API for Indian languages (
|
7
|
+
version = "0.1.6"
|
8
|
+
description = "Multimodal API for Indian languages (Chat, Vision, TTS, ASR, Translate, Docs)"
|
9
9
|
authors = [
|
10
10
|
{ name="sachin", email="python@dwani.ai" }
|
11
11
|
]
|
dwani-0.1.5/README.md
DELETED
@@ -1,73 +0,0 @@
|
|
1
|
-
# dwani.ai - python library
|
2
|
-
|
3
|
-
|
4
|
-
### Install the library
|
5
|
-
```bash
|
6
|
-
pip install dwani
|
7
|
-
```
|
8
|
-
|
9
|
-
### Setup the credentials
|
10
|
-
```python
|
11
|
-
import dwani
|
12
|
-
import os
|
13
|
-
|
14
|
-
dwani.api_key = os.getenv("DWANI_API_KEY")
|
15
|
-
|
16
|
-
dwani.api_base = os.getenv("DWANI_API_BASE_URL")
|
17
|
-
```
|
18
|
-
|
19
|
-
### Examples
|
20
|
-
|
21
|
-
#### Text Query
|
22
|
-
```python
|
23
|
-
resp = dwani.Chat.create(prompt="Hello!", src_lang="eng_Latn", tgt_lang="kan_Knda")
|
24
|
-
print(resp)
|
25
|
-
```
|
26
|
-
|
27
|
-
#### Vision Query
|
28
|
-
```python
|
29
|
-
result = dwani.Vision.caption(
|
30
|
-
file_path="image.png",
|
31
|
-
query="Describe this logo",
|
32
|
-
src_lang="eng_Latn",
|
33
|
-
tgt_lang="kan_Knda"
|
34
|
-
)
|
35
|
-
print(result)
|
36
|
-
```
|
37
|
-
|
38
|
-
#### Speech to Text - Automatic Speech Recognition (ASR)
|
39
|
-
```python
|
40
|
-
result = dwani.ASR.transcribe(file_path="kannada_sample.wav", language="kannada")
|
41
|
-
print(result)
|
42
|
-
```
|
43
|
-
|
44
|
-
#### Text to Speech - Speech Synthesis
|
45
|
-
|
46
|
-
```python
|
47
|
-
response = dwani.Audio.speech(input="ಕರ್ನಾಟಕ ದ ರಾಜಧಾನಿ ಯಾವುದು", response_format="mp3")
|
48
|
-
with open("output.mp3", "wb") as f:
|
49
|
-
f.write(response)
|
50
|
-
```
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
- Website -> [dwani.ai](https://dwani.ai)
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
#### Contact
|
59
|
-
- For any questions or issues, please open an issue on GitHub or contact us via email.
|
60
|
-
- For collaborations
|
61
|
-
- Join the discord group - [invite link](https://discord.gg/WZMCerEZ2P)
|
62
|
-
<!--
|
63
|
-
## local development
|
64
|
-
pip install -e .
|
65
|
-
|
66
|
-
|
67
|
-
pip install twine build
|
68
|
-
rm -rf dist/
|
69
|
-
python -m build
|
70
|
-
|
71
|
-
python -m twine upload dist/*
|
72
|
-
|
73
|
-
-->
|
dwani-0.1.5/dwani/client.py
DELETED
@@ -1,46 +0,0 @@
|
|
1
|
-
import os
|
2
|
-
import requests
|
3
|
-
from .exceptions import DhwaniAPIError
|
4
|
-
|
5
|
-
class DhwaniClient:
|
6
|
-
def __init__(self, api_key=None, api_base=None):
|
7
|
-
self.api_key = api_key or os.getenv("DWANI_API_KEY")
|
8
|
-
self.api_base = api_base or os.getenv("DWANI_API_BASE_URL", "http://localhost:8000")
|
9
|
-
if not self.api_key:
|
10
|
-
raise ValueError("DHWANI_API_KEY not set")
|
11
|
-
|
12
|
-
def _headers(self):
|
13
|
-
return {"X-API-Key": self.api_key}
|
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
|
-
def translate(self, sentences, src_lang, tgt_lang, **kwargs):
|
20
|
-
from .translate import run_translate
|
21
|
-
return run_translate(self, sentences=sentences,src_lang= src_lang, tgt_lang=tgt_lang, **kwargs)
|
22
|
-
|
23
|
-
def speech(self, *args, **kwargs):
|
24
|
-
from .audio import audio_speech
|
25
|
-
return audio_speech(self, *args, **kwargs)
|
26
|
-
|
27
|
-
def caption(self, file_path, query="describe the image", src_lang="eng_Latn", tgt_lang="kan_Knda"):
|
28
|
-
from .vision import vision_caption
|
29
|
-
return vision_caption(self, file_path, query, src_lang, tgt_lang)
|
30
|
-
|
31
|
-
def transcribe(self, *args, **kwargs):
|
32
|
-
from .asr import asr_transcribe
|
33
|
-
return asr_transcribe(self, *args, **kwargs)
|
34
|
-
|
35
|
-
def document_ocr(self, file_path, language=None):
|
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)
|
42
|
-
|
43
|
-
def document_summarize(self, file_path, language=None):
|
44
|
-
from .docs import document_summarize
|
45
|
-
return document_summarize(self, file_path, language)
|
46
|
-
|
dwani-0.1.5/dwani/docs.py
DELETED
@@ -1,70 +0,0 @@
|
|
1
|
-
import requests
|
2
|
-
from .exceptions import DhwaniAPIError
|
3
|
-
|
4
|
-
def document_ocr(client, file_path, language=None):
|
5
|
-
"""OCR a document (image/PDF) and return extracted text."""
|
6
|
-
with open(file_path, "rb") as f:
|
7
|
-
files = {"file": f}
|
8
|
-
data = {}
|
9
|
-
if language:
|
10
|
-
data["language"] = language
|
11
|
-
resp = requests.post(
|
12
|
-
f"{client.api_base}/v1/document/ocr",
|
13
|
-
headers=client._headers(),
|
14
|
-
files=files,
|
15
|
-
data=data
|
16
|
-
)
|
17
|
-
if resp.status_code != 200:
|
18
|
-
raise DhwaniAPIError(resp)
|
19
|
-
return resp.json()
|
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."""
|
23
|
-
with open(file_path, "rb") as f:
|
24
|
-
files = {"file": f}
|
25
|
-
data = {
|
26
|
-
"src_lang": src_lang,
|
27
|
-
"tgt_lang": tgt_lang
|
28
|
-
}
|
29
|
-
resp = requests.post(
|
30
|
-
f"{client.api_base}/v1/document/translate",
|
31
|
-
headers=client._headers(),
|
32
|
-
files=files,
|
33
|
-
data=data
|
34
|
-
)
|
35
|
-
if resp.status_code != 200:
|
36
|
-
raise DhwaniAPIError(resp)
|
37
|
-
return resp.json()
|
38
|
-
|
39
|
-
def document_summarize(client, file_path, language=None):
|
40
|
-
"""Summarize a document (image/PDF/text)."""
|
41
|
-
with open(file_path, "rb") as f:
|
42
|
-
files = {"file": f}
|
43
|
-
data = {}
|
44
|
-
if language:
|
45
|
-
data["language"] = language
|
46
|
-
resp = requests.post(
|
47
|
-
f"{client.api_base}/v1/document/summarize",
|
48
|
-
headers=client._headers(),
|
49
|
-
files=files,
|
50
|
-
data=data
|
51
|
-
)
|
52
|
-
if resp.status_code != 200:
|
53
|
-
raise DhwaniAPIError(resp)
|
54
|
-
return resp.json()
|
55
|
-
|
56
|
-
class Documents:
|
57
|
-
@staticmethod
|
58
|
-
def ocr(file_path, language=None):
|
59
|
-
from . import _get_client
|
60
|
-
return _get_client().document_ocr(file_path, language)
|
61
|
-
|
62
|
-
@staticmethod
|
63
|
-
def translate(file_path, src_lang, tgt_lang):
|
64
|
-
from . import _get_client
|
65
|
-
return _get_client().document_translate(file_path, src_lang, tgt_lang)
|
66
|
-
|
67
|
-
@staticmethod
|
68
|
-
def summarize(file_path, language=None):
|
69
|
-
from . import _get_client
|
70
|
-
return _get_client().document_summarize(file_path, language)
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|