dwani 0.1.4__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/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_URL", "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,6 +15,10 @@ 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
+
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)
18
22
 
19
23
  def speech(self, *args, **kwargs):
20
24
  from .audio import audio_speech
@@ -27,6 +31,7 @@ class DhwaniClient:
27
31
  def transcribe(self, *args, **kwargs):
28
32
  from .asr import asr_transcribe
29
33
  return asr_transcribe(self, *args, **kwargs)
34
+
30
35
  def document_ocr(self, file_path, language=None):
31
36
  from .docs import document_ocr
32
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]
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: dwani
3
- Version: 0.1.4
3
+ Version: 0.1.5
4
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
@@ -37,12 +37,12 @@ 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
@@ -50,12 +50,51 @@ import os
50
50
  dwani.api_key = os.getenv("DWANI_API_KEY")
51
51
 
52
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 .
@@ -2,12 +2,13 @@ dwani/__init__.py,sha256=P2pyHkZ7JHn6lHSEbCdV4hjYAwCOXHN3RbsNIU0F5PE,1084
2
2
  dwani/asr.py,sha256=Y5Mbv1KsvhfXNZacMZycUHPn79NRQC-XPH0j9SYPUSY,590
3
3
  dwani/audio.py,sha256=Q9vw4uBxGy1vQzmiZjZGrY8hkAEQNkGhjz5OcnpFEQQ,888
4
4
  dwani/chat.py,sha256=WFuEShNd4nd6KUbIZTkm3eyPGoP33GepOLJax86nNn8,720
5
- dwani/client.py,sha256=DmGF93Doibam-rPuV64XlyIwgiWrDJigXZNBCkPz-ho,1601
5
+ dwani/client.py,sha256=saQxRBcERSMoCMOqBIe_IqRygh9-e4KxF3iZZvBEZDc,1826
6
6
  dwani/docs.py,sha256=2B87KqshPl7-2gDJAJxdvcgmPWuC2IQ1FcsDIyeVJPg,2202
7
7
  dwani/exceptions.py,sha256=qEN5ukqlnN7v-kHNEnISWFMpPMt6uTft9mPsTXJ4LVA,227
8
+ dwani/translate.py,sha256=nYB62DLoPf7Weg26aNtpoEpyasDIsArVTzl5xKPp6eI,972
8
9
  dwani/vision.py,sha256=JtMSS0hI-8gxtLugVP10__enZsPPy8jheMyWXvrGrdw,1015
9
- dwani-0.1.4.dist-info/licenses/LICENSE,sha256=IAD8tbwWZbPWHXgYjabHoMv0aaUzZUYzYiEbfhTCisY,1070
10
- dwani-0.1.4.dist-info/METADATA,sha256=MZunthMWfUpXPchujVFu20UZDSURcnSd7FRWLt7KCos,2158
11
- dwani-0.1.4.dist-info/WHEEL,sha256=DnLRTWE75wApRYVsjgc6wsVswC54sMSJhAEd4xhDpBk,91
12
- dwani-0.1.4.dist-info/top_level.txt,sha256=AM5EhkyuO_EXQFR9JIxEV6tAYMCCyc-a1dLifpCGBUk,6
13
- dwani-0.1.4.dist-info/RECORD,,
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