debasishmohanty commited on
Commit
520b4ab
·
1 Parent(s): 2754945

modified handler

Browse files
Files changed (1) hide show
  1. handler.py +69 -71
handler.py CHANGED
@@ -7,72 +7,72 @@ import shutil
7
  from TTS.utils.synthesizer import Synthesizer
8
 
9
 
10
- def get_or_model():
11
- # URL of the ZIP file to download
12
- if os.path.exists('./or'):
13
- return
14
- zip_file_url = 'https://github.com/AI4Bharat/Indic-TTS/releases/download/v1-checkpoints-release/or.zip'
15
-
16
- # Send a GET request to download the file
17
- response = requests.get(zip_file_url)
18
-
19
- try:
20
- if response.status_code == 200:
21
- # Extract the content from the response
22
- zip_data = io.BytesIO(response.content)
23
 
24
- # Unzip the file
25
- with zipfile.ZipFile(zip_data, 'r') as zip_ref:
26
- # Replace 'path_to_extract' with the directory path where you want to extract the contents
27
- zip_ref.extractall('./')
28
- print("ZIP file downloaded and extracted successfully.")
29
- else:
30
- print("Failed to download ZIP file.")
31
- except Exception as e:
32
- print(f"Error occurred while downloading and extracting ZIP file: {e}")
33
-
34
- def get_indic_tts_library():
35
-
36
- if os.path.exists("./IndicTTS"):
37
- print("IndicTTS library already exists, skipping download.")
38
- return
39
-
40
- # GitHub repository URL
41
- github_repo_url = 'https://github.com/TRY-ER/IndicTTSCustom.git'
42
-
43
- # Prepare target directory
44
- try:
45
- os.makedirs("./IndicTTS", exist_ok=True)
46
- except OSError as e:
47
- print(f"Error creating directory: {e}")
48
- return
49
-
50
- # Execute the git clone command
51
- try:
52
- subprocess.run(['git', 'clone', github_repo_url, './IndicTTS'], check=True)
53
- print("IndicTTS library downloaded successfully.")
54
- except subprocess.CalledProcessError as e:
55
- print(f"Failed to download IndicTTS library: {e}")
56
-
57
- def replace_json():
58
-
59
- # Source file path
60
- source_file = './IndicTTSCustom/custom_config.json'
61
-
62
- # Destination file path (where you want to move the file)
63
- destination_file = './or/fastpitch/config.json'
64
-
65
- # Move the file
66
- try:
67
- # Replace the file if it already exists at the destination
68
- shutil.copy(source_file, destination_file)
69
- print(f"File moved from {source_file} to {destination_file} successfully.")
70
- except FileNotFoundError:
71
- print("Source file not found.")
72
- except PermissionError:
73
- print("Permission denied.")
74
- except shutil.Error as e:
75
- print(f"Error: {e}")
76
 
77
 
78
  # def pred_audio():
@@ -105,16 +105,14 @@ def replace_json():
105
  # with open("odia_audio_female.wav", "wb") as f:
106
  # f.write(byte_io.read())
107
 
108
-
109
- get_or_model()
110
- get_indic_tts_library()
111
- replace_json()
112
-
113
  from IndicTTS.inference.src.inference import TextToSpeechEngine
 
114
 
115
  class EndpointHandler():
116
  def __init__(self,path=""):
117
  self.path = path
 
 
118
  models = {}
119
  odia_model = Synthesizer(
120
  tts_checkpoint="./or/fastpitch/best_model.pth",
@@ -134,7 +132,7 @@ class EndpointHandler():
134
  output_lang_code = data["inputs"]["output_lang_code"]
135
  speaker_gender = data["inputs"]["speaker_gender"]
136
  audio_array= self.engine.infer_from_text(
137
- input_text=input,
138
  lang=output_lang_code,
139
  speaker_name=speaker_gender,
140
  )
 
7
  from TTS.utils.synthesizer import Synthesizer
8
 
9
 
10
+ # def get_or_model():
11
+ # # URL of the ZIP file to download
12
+ # if os.path.exists('./or'):
13
+ # return
14
+ # zip_file_url = 'https://github.com/AI4Bharat/Indic-TTS/releases/download/v1-checkpoints-release/or.zip'
15
+
16
+ # # Send a GET request to download the file
17
+ # response = requests.get(zip_file_url)
18
+
19
+ # try:
20
+ # if response.status_code == 200:
21
+ # # Extract the content from the response
22
+ # zip_data = io.BytesIO(response.content)
23
 
24
+ # # Unzip the file
25
+ # with zipfile.ZipFile(zip_data, 'r') as zip_ref:
26
+ # # Replace 'path_to_extract' with the directory path where you want to extract the contents
27
+ # zip_ref.extractall('./')
28
+ # print("ZIP file downloaded and extracted successfully.")
29
+ # else:
30
+ # print("Failed to download ZIP file.")
31
+ # except Exception as e:
32
+ # print(f"Error occurred while downloading and extracting ZIP file: {e}")
33
+
34
+ # def get_indic_tts_library():
35
+
36
+ # if os.path.exists("./IndicTTS"):
37
+ # print("IndicTTS library already exists, skipping download.")
38
+ # return
39
+
40
+ # # GitHub repository URL
41
+ # github_repo_url = 'https://github.com/TRY-ER/IndicTTSCustom.git'
42
+
43
+ # # Prepare target directory
44
+ # try:
45
+ # os.makedirs("./IndicTTS", exist_ok=True)
46
+ # except OSError as e:
47
+ # print(f"Error creating directory: {e}")
48
+ # return
49
+
50
+ # # Execute the git clone command
51
+ # try:
52
+ # subprocess.run(['git', 'clone', github_repo_url, './IndicTTS'], check=True)
53
+ # print("IndicTTS library downloaded successfully.")
54
+ # except subprocess.CalledProcessError as e:
55
+ # print(f"Failed to download IndicTTS library: {e}")
56
+
57
+ # def replace_json():
58
+
59
+ # # Source file path
60
+ # source_file = './IndicTTSCustom/custom_config.json'
61
+
62
+ # # Destination file path (where you want to move the file)
63
+ # destination_file = './or/fastpitch/config.json'
64
+
65
+ # # Move the file
66
+ # try:
67
+ # # Replace the file if it already exists at the destination
68
+ # shutil.copy(source_file, destination_file)
69
+ # print(f"File moved from {source_file} to {destination_file} successfully.")
70
+ # except FileNotFoundError:
71
+ # print("Source file not found.")
72
+ # except PermissionError:
73
+ # print("Permission denied.")
74
+ # except shutil.Error as e:
75
+ # print(f"Error: {e}")
76
 
77
 
78
  # def pred_audio():
 
105
  # with open("odia_audio_female.wav", "wb") as f:
106
  # f.write(byte_io.read())
107
 
 
 
 
 
 
108
  from IndicTTS.inference.src.inference import TextToSpeechEngine
109
+ import torch
110
 
111
  class EndpointHandler():
112
  def __init__(self,path=""):
113
  self.path = path
114
+ print(f"python version>> ",{torch.__version__})
115
+ print(f"cuda version>> ",{torch.cuda.get_device_capability(0)[0]})
116
  models = {}
117
  odia_model = Synthesizer(
118
  tts_checkpoint="./or/fastpitch/best_model.pth",
 
132
  output_lang_code = data["inputs"]["output_lang_code"]
133
  speaker_gender = data["inputs"]["speaker_gender"]
134
  audio_array= self.engine.infer_from_text(
135
+ input_text=input_text,
136
  lang=output_lang_code,
137
  speaker_name=speaker_gender,
138
  )