dwani 0.1.3__py3-none-any.whl → 0.1.5__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/asr.py CHANGED
@@ -4,7 +4,7 @@ def asr_transcribe(client, file_path, language):
4
4
  with open(file_path, "rb") as f:
5
5
  files = {"file": f}
6
6
  resp = requests.post(
7
- f"{client.api_base}/transcribe/?language={language}",
7
+ f"{client.api_base}/v1/transcribe/?language={language}",
8
8
  headers=client._headers(),
9
9
  files=files
10
10
  )
@@ -18,20 +18,3 @@ class ASR:
18
18
  from . import _get_client
19
19
  return _get_client().transcribe(*args, **kwargs)
20
20
 
21
-
22
- '''
23
- from .docs import Documents
24
-
25
- class documents:
26
- @staticmethod
27
- def ocr(file_path, language=None):
28
- return _get_client().document_ocr(file_path, language)
29
-
30
- @staticmethod
31
- def translate(file_path, src_lang, tgt_lang):
32
- return _get_client().document_translate(file_path, src_lang, tgt_lang)
33
-
34
- @staticmethod
35
- def summarize(file_path, language=None):
36
- return _get_client().document_summarize(file_path, language)
37
- '''
dwani/audio.py CHANGED
@@ -1,16 +1,16 @@
1
1
  from .exceptions import DhwaniAPIError
2
2
  import requests
3
- def audio_speech(client, input, voice, model, response_format="mp3", output_file=None):
4
- data = {
3
+
4
+ def audio_speech(client, input, response_format="mp3", output_file=None):
5
+ params = {
5
6
  "input": input,
6
- "voice": voice,
7
- "model": model,
8
7
  "response_format": response_format
9
8
  }
10
9
  resp = requests.post(
11
10
  f"{client.api_base}/v1/audio/speech",
12
- headers={**client._headers(), "Content-Type": "application/json"},
13
- json=data,
11
+ headers={**client._headers(), "accept": "application/json"},
12
+ params=params,
13
+ data='', # Empty body, as in the curl example
14
14
  stream=True
15
15
  )
16
16
  if resp.status_code != 200:
dwani/client.py CHANGED
@@ -5,7 +5,7 @@ from .exceptions import DhwaniAPIError
5
5
  class DhwaniClient:
6
6
  def __init__(self, api_key=None, api_base=None):
7
7
  self.api_key = api_key or os.getenv("DWANI_API_KEY")
8
- self.api_base = api_base or os.getenv("DWANI_API_BASE", "http://localhost:7860")
8
+ self.api_base = api_base or os.getenv("DWANI_API_BASE_URL", "http://localhost:8000")
9
9
  if not self.api_key:
10
10
  raise ValueError("DHWANI_API_KEY not set")
11
11
 
@@ -15,19 +15,23 @@ class DhwaniClient:
15
15
  def chat(self, prompt, src_lang, tgt_lang, **kwargs):
16
16
  from .chat import chat_create
17
17
  return chat_create(self, prompt, src_lang, tgt_lang, **kwargs)
18
-
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)
19
22
 
20
23
  def speech(self, *args, **kwargs):
21
24
  from .audio import audio_speech
22
25
  return audio_speech(self, *args, **kwargs)
23
26
 
24
- def caption(self, *args, **kwargs):
27
+ def caption(self, file_path, query="describe the image", src_lang="eng_Latn", tgt_lang="kan_Knda"):
25
28
  from .vision import vision_caption
26
- return vision_caption(self, *args, **kwargs)
29
+ return vision_caption(self, file_path, query, src_lang, tgt_lang)
27
30
 
28
31
  def transcribe(self, *args, **kwargs):
29
32
  from .asr import asr_transcribe
30
33
  return asr_transcribe(self, *args, **kwargs)
34
+
31
35
  def document_ocr(self, file_path, language=None):
32
36
  from .docs import document_ocr
33
37
  return document_ocr(self, file_path, language)
dwani/translate.py ADDED
@@ -0,0 +1,29 @@
1
+ from .exceptions import DhwaniAPIError
2
+ import requests
3
+
4
+ def run_translate(client, sentences, src_lang, tgt_lang, **kwargs):
5
+ url = f"{client.api_base}/v1/translate"
6
+ payload = {
7
+ "sentences": sentences,
8
+ "src_lang": src_lang,
9
+ "tgt_lang": tgt_lang
10
+ }
11
+ payload.update(kwargs)
12
+ resp = requests.post(
13
+ url,
14
+ headers={**client._headers(), "Content-Type": "application/json", "accept": "application/json"},
15
+ json=payload
16
+ )
17
+ if resp.status_code != 200:
18
+ raise DhwaniAPIError(resp)
19
+ return resp.json()
20
+
21
+ class Translate:
22
+ @staticmethod
23
+ def translate(sentence, src_lang, tgt_lang, **kwargs):
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]
dwani/vision.py CHANGED
@@ -1,12 +1,22 @@
1
1
  from .exceptions import DhwaniAPIError
2
2
  import requests
3
- def vision_caption(client, file_path, length="short"):
3
+ def vision_caption(client, file_path, query="describe the image", src_lang="eng_Latn", tgt_lang="kan_Knda"):
4
+ # Build the endpoint using the client's api_base
5
+ url = (
6
+ f"{client.api_base}/v1/indic_visual_query"
7
+ f"?src_lang={src_lang}&tgt_lang={tgt_lang}"
8
+ )
9
+ headers = {
10
+ **client._headers(),
11
+ "accept": "application/json"
12
+ # Note: 'Content-Type' will be set automatically by requests when using 'files'
13
+ }
4
14
  with open(file_path, "rb") as f:
5
- files = {"file": f}
6
- data = {"length": length}
15
+ files = {"file": (file_path, f, "image/png")}
16
+ data = {"query": query}
7
17
  resp = requests.post(
8
- f"{client.api_base}/caption/",
9
- headers=client._headers(),
18
+ url,
19
+ headers=headers,
10
20
  files=files,
11
21
  data=data
12
22
  )
@@ -1,7 +1,7 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: dwani
3
- Version: 0.1.3
4
- Summary: Multimodal AI server for Indian languages (speech, vision, LLMs, TTS, ASR, etc.)
3
+ Version: 0.1.5
4
+ Summary: Multimodal API for Indian languages (speech, vision, LLMs, TTS, ASR, etc.)
5
5
  Author-email: sachin <python@dwani.ai>
6
6
  License: MIT License
7
7
 
@@ -28,7 +28,7 @@ License: MIT License
28
28
  Project-URL: Homepage, https://github.com/dwani-ai/dwani-python
29
29
  Project-URL: Source, https://github.com/dwani-ai/dwani-python
30
30
  Project-URL: Issues, https://github.com/dwani-ai/dwani-python/issues
31
- Requires-Python: >=3.10
31
+ Requires-Python: >=3.8
32
32
  Description-Content-Type: text/markdown
33
33
  License-File: LICENSE
34
34
  Requires-Dist: requests>=2.25.0
@@ -37,25 +37,64 @@ Dynamic: license-file
37
37
  # dwani.ai - python library
38
38
 
39
39
 
40
+ ### Install the library
40
41
  ```bash
41
42
  pip install dwani
42
43
  ```
43
44
 
44
-
45
-
45
+ ### Setup the credentials
46
46
  ```python
47
47
  import dwani
48
48
  import os
49
49
 
50
50
  dwani.api_key = os.getenv("DWANI_API_KEY")
51
51
 
52
- dwani.api_base = os.getenv("DWANI_API_BASE")
52
+ dwani.api_base = os.getenv("DWANI_API_BASE_URL")
53
+ ```
53
54
 
54
- resp = dwani.Chat.create("Hello!", "eng_Latn", "kan_Knda")
55
+ ### Examples
56
+
57
+ #### Text Query
58
+ ```python
59
+ resp = dwani.Chat.create(prompt="Hello!", src_lang="eng_Latn", tgt_lang="kan_Knda")
55
60
  print(resp)
56
61
  ```
57
62
 
63
+ #### Vision Query
64
+ ```python
65
+ result = dwani.Vision.caption(
66
+ file_path="image.png",
67
+ query="Describe this logo",
68
+ src_lang="eng_Latn",
69
+ tgt_lang="kan_Knda"
70
+ )
71
+ print(result)
72
+ ```
73
+
74
+ #### Speech to Text - Automatic Speech Recognition (ASR)
75
+ ```python
76
+ result = dwani.ASR.transcribe(file_path="kannada_sample.wav", language="kannada")
77
+ print(result)
78
+ ```
79
+
80
+ #### Text to Speech - Speech Synthesis
81
+
82
+ ```python
83
+ response = dwani.Audio.speech(input="ಕರ್ನಾಟಕ ದ ರಾಜಧಾನಿ ಯಾವುದು", response_format="mp3")
84
+ with open("output.mp3", "wb") as f:
85
+ f.write(response)
86
+ ```
87
+
88
+
89
+
90
+ - Website -> [dwani.ai](https://dwani.ai)
91
+
92
+
58
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)
59
98
  <!--
60
99
  ## local development
61
100
  pip install -e .
@@ -0,0 +1,14 @@
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,,
@@ -1,13 +0,0 @@
1
- dwani/__init__.py,sha256=P2pyHkZ7JHn6lHSEbCdV4hjYAwCOXHN3RbsNIU0F5PE,1084
2
- dwani/asr.py,sha256=Xe62t8dNQy9gRkn4LyjaagOXjKZ90aexYEL2D-oVP2U,1042
3
- dwani/audio.py,sha256=lyFjYAv4EsDIHPbopv9Lf5LJIzuJEuoBO9H37TVGaUo,894
4
- dwani/chat.py,sha256=WFuEShNd4nd6KUbIZTkm3eyPGoP33GepOLJax86nNn8,720
5
- dwani/client.py,sha256=qtXDAv9t-Eu5HGvH4ubrcmIIH8VgrTHn0c_Ozm4-cmQ,1513
6
- dwani/docs.py,sha256=2B87KqshPl7-2gDJAJxdvcgmPWuC2IQ1FcsDIyeVJPg,2202
7
- dwani/exceptions.py,sha256=qEN5ukqlnN7v-kHNEnISWFMpPMt6uTft9mPsTXJ4LVA,227
8
- dwani/vision.py,sha256=xi9gVsL8MA8VQYXIV99uqKuxYfs1kWu4tvqzbe95F1Y,623
9
- dwani-0.1.3.dist-info/licenses/LICENSE,sha256=IAD8tbwWZbPWHXgYjabHoMv0aaUzZUYzYiEbfhTCisY,1070
10
- dwani-0.1.3.dist-info/METADATA,sha256=KALRQIuxWFjbHHsF8QAdHHs76DVcfSAUPoWsGBcOsFs,2161
11
- dwani-0.1.3.dist-info/WHEEL,sha256=DnLRTWE75wApRYVsjgc6wsVswC54sMSJhAEd4xhDpBk,91
12
- dwani-0.1.3.dist-info/top_level.txt,sha256=AM5EhkyuO_EXQFR9JIxEV6tAYMCCyc-a1dLifpCGBUk,6
13
- dwani-0.1.3.dist-info/RECORD,,
File without changes