Simonlob commited on
Commit
7298e06
·
verified ·
1 Parent(s): c134bb3

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -0
app.py CHANGED
@@ -13,6 +13,9 @@ from matcha.text import sequence_to_text, text_to_sequence
13
  from matcha.utils.utils import intersperse
14
  import gradio as gr
15
  import requests
 
 
 
16
 
17
  def download_file(url, save_path):
18
  response = requests.get(url)
@@ -28,6 +31,12 @@ save_generator_path = './checkpoints/generator'
28
  download_file(url_checkpoint, save_checkpoint_path)
29
  download_file(url_generator, save_generator_path)
30
 
 
 
 
 
 
 
31
  def load_matcha( checkpoint_path, device):
32
  model = MatchaTTS.load_from_checkpoint(checkpoint_path, map_location=device)
33
  _ = model.eval()
@@ -49,6 +58,7 @@ def load_vocoder(checkpoint_path, device):
49
 
50
  def process_text(i: int, text: str, device: torch.device):
51
  print(f"[{i}] - Input text: {text}")
 
52
  x = torch.tensor(
53
  intersperse(text_to_sequence(text, ["kyrgyz_cleaners"]), 0),
54
  dtype=torch.long,
 
13
  from matcha.utils.utils import intersperse
14
  import gradio as gr
15
  import requests
16
+ import json
17
+ from datetime import datetime
18
+
19
 
20
  def download_file(url, save_path):
21
  response = requests.get(url)
 
31
  download_file(url_checkpoint, save_checkpoint_path)
32
  download_file(url_generator, save_generator_path)
33
 
34
+ def log_event(input_text, log_file="usage_log.json"):
35
+ event_data = {'timestamp': datetime.now().isoformat(),
36
+ 'text': input_text}
37
+ with open(log_file, "a") as file:
38
+ file.write(json.dumps(event_data) + "\n")
39
+
40
  def load_matcha( checkpoint_path, device):
41
  model = MatchaTTS.load_from_checkpoint(checkpoint_path, map_location=device)
42
  _ = model.eval()
 
58
 
59
  def process_text(i: int, text: str, device: torch.device):
60
  print(f"[{i}] - Input text: {text}")
61
+ log_event(text)
62
  x = torch.tensor(
63
  intersperse(text_to_sequence(text, ["kyrgyz_cleaners"]), 0),
64
  dtype=torch.long,