MitchellKil commited on
Commit
fbc18f1
·
verified ·
1 Parent(s): 8c9551b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +11 -12
app.py CHANGED
@@ -11,18 +11,18 @@ from huggingface_hub import hf_hub_download
11
  api = HfApi()
12
  app = FastAPI()
13
 
14
- MODEL_NAME = "MitchellKil/gaelic-ipa-byt5" # my fine tuned model
15
  DATASET_REPO = "mitchellkil/gaelic-app-feedback" # file to write feedback to
16
 
17
- HF_TOKEN = os.environ["HF_TOKEN"] # set in Space secrets
18
 
19
 
20
- print("Loading Gaelic → IPA model from HF")
21
 
22
  device = "cuda" if torch.cuda.is_available() else "cpu"
23
 
24
- tokenizer = AutoTokenizer.from_pretrained(MODEL_NAME)
25
- model = AutoModelForSeq2SeqLM.from_pretrained(MODEL_NAME).to(device)
26
  model.eval()
27
 
28
  print("Model loaded")
@@ -33,13 +33,13 @@ class TextRequest(BaseModel):
33
 
34
  def text_to_ipa(text: str) -> str:
35
  # Input text - > target text for trained model
36
- prompt = f"convert this from Gaelic to IPA: {text}"
37
 
38
  inputs = tokenizer(
39
  prompt,
40
  return_tensors="pt",
41
  truncation=True,
42
- max_length=128
43
  ).to(device)
44
 
45
  with torch.no_grad():
@@ -83,10 +83,9 @@ def save_feedback(data: Feedback):
83
  )
84
  with open(local_file, "r", encoding="utf-8") as f:
85
  lines = f.readlines()
86
- except:
87
- lines = []
88
 
89
- lines.append(json.dumps(entry) + "\n") # Append
90
 
91
  temp_path = "feedback_temp.jsonl" # create temp
92
  with open(temp_path, "w", encoding="utf-8") as f:
@@ -98,8 +97,8 @@ def save_feedback(data: Feedback):
98
  repo_id=DATASET_REPO,
99
  repo_type="dataset",
100
  token=HF_TOKEN,
101
- commit_message="Append new feedback"
102
  )
103
 
104
- return {"status": "Thank you for your feedback"}
105
 
 
11
  api = HfApi()
12
  app = FastAPI()
13
 
14
+ modelName = "MitchellKil/gaelic-ipa-byt5" # my fine tuned model
15
  DATASET_REPO = "mitchellkil/gaelic-app-feedback" # file to write feedback to
16
 
17
+ HF_TOKEN = os.environ["HF_TOKEN"] # set in secrets
18
 
19
 
20
+ print("Loading IPA model")
21
 
22
  device = "cuda" if torch.cuda.is_available() else "cpu"
23
 
24
+ tokenizer = AutoTokenizer.from_pretrained(modelName)
25
+ model = AutoModelForSeq2SeqLM.from_pretrained(modelName).to(device)
26
  model.eval()
27
 
28
  print("Model loaded")
 
33
 
34
  def text_to_ipa(text: str) -> str:
35
  # Input text - > target text for trained model
36
+ prompt = f"convert Gaelic to IPA: {text}"
37
 
38
  inputs = tokenizer(
39
  prompt,
40
  return_tensors="pt",
41
  truncation=True,
42
+ max_length=110
43
  ).to(device)
44
 
45
  with torch.no_grad():
 
83
  )
84
  with open(local_file, "r", encoding="utf-8") as f:
85
  lines = f.readlines()
86
+
 
87
 
88
+ lines.append(json.dumps(entry) + "\n") # append
89
 
90
  temp_path = "feedback_temp.jsonl" # create temp
91
  with open(temp_path, "w", encoding="utf-8") as f:
 
97
  repo_id=DATASET_REPO,
98
  repo_type="dataset",
99
  token=HF_TOKEN,
100
+ commit_message="New feedback added"
101
  )
102
 
103
+ return {"status": "Thanks for your feedback"}
104