Spaces:
Runtime error
Runtime error
Rohan Kumar Singh commited on
Commit ·
65d4d2c
1
Parent(s): 1a1d13a
initial commit
Browse files- .gitattributes +3 -0
- __pycache__/app.cpython-310.pyc +0 -0
- __pycache__/inference.cpython-310.pyc +0 -0
- all-data-200k (1).ipynb +0 -0
- app.py +14 -0
- dockerfile +0 -0
- inference.py +33 -0
- requirements.txt +7 -0
- translator/fingerprint.pb +3 -0
- translator/saved_model.pb +3 -0
- translator/variables/variables.data-00000-of-00001 +3 -0
- translator/variables/variables.index +0 -0
- vocab_data.pkl +3 -0
.gitattributes
CHANGED
|
@@ -33,3 +33,6 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
|
| 33 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
| 34 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
| 35 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
|
|
|
|
|
|
|
|
|
|
|
| 33 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
| 34 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
| 35 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
| 36 |
+
vocab_data.pkl filter=lfs diff=lfs merge=lfs -text
|
| 37 |
+
translator/saved_model.pb filter=lfs diff=lfs merge=lfs -text
|
| 38 |
+
translator/variables/variables.data-00000-of-00001 filter=lfs diff=lfs merge=lfs -text
|
__pycache__/app.cpython-310.pyc
ADDED
|
Binary file (629 Bytes). View file
|
|
|
__pycache__/inference.cpython-310.pyc
ADDED
|
Binary file (1.32 kB). View file
|
|
|
all-data-200k (1).ipynb
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
app.py
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from fastapi import FastAPI
|
| 2 |
+
from inference import outcome
|
| 3 |
+
import warnings
|
| 4 |
+
warnings.filterwarnings("ignore")
|
| 5 |
+
|
| 6 |
+
app=FastAPI()
|
| 7 |
+
|
| 8 |
+
@app.get('/')
|
| 9 |
+
def index():
|
| 10 |
+
return {"message":"Welcome to Hinglish Translator"}
|
| 11 |
+
|
| 12 |
+
@app.post('/predict')
|
| 13 |
+
def predict(input: str):
|
| 14 |
+
return {"result":outcome(input)}
|
dockerfile
ADDED
|
File without changes
|
inference.py
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import pickle
|
| 2 |
+
import pandas as pd
|
| 3 |
+
import numpy
|
| 4 |
+
#import logging, os
|
| 5 |
+
#logging.disable(logging.WARNING)
|
| 6 |
+
#os.environ["TF_CPP_MIN_LOG_LEVEL"] = "3"
|
| 7 |
+
import tensorflow as tf
|
| 8 |
+
import tensorflow_text as tf_text
|
| 9 |
+
from metaphone import doublemetaphone
|
| 10 |
+
import re
|
| 11 |
+
|
| 12 |
+
with open('vocab_data.pkl', 'rb') as fp:
|
| 13 |
+
hin_vocab = pickle.load(fp)
|
| 14 |
+
vocab_keys=[l for l in hin_vocab]
|
| 15 |
+
#all_data_vocab_53k_mixed_batch_v2
|
| 16 |
+
reloaded = tf.saved_model.load("translator")
|
| 17 |
+
|
| 18 |
+
def t_text(line):
|
| 19 |
+
line=re.sub("[.!?\\-\'\"]", "",line).lower().strip()
|
| 20 |
+
string=''
|
| 21 |
+
for j in line.split(' '):
|
| 22 |
+
if doublemetaphone(j)[0]+'*'+doublemetaphone(j[::-1])[0]+'*'+j[:2]+'*'+j[len(j)-1:] in vocab_keys:
|
| 23 |
+
string=string+list(hin_vocab[doublemetaphone(j)[0]+'*'+doublemetaphone(j[::-1])[0]+'*'+j[:2]+'*'+j[len(j)-1:]])[0]+' '
|
| 24 |
+
else:
|
| 25 |
+
string=string+j+' '
|
| 26 |
+
return string.lower().strip()
|
| 27 |
+
|
| 28 |
+
def outcome(input):
|
| 29 |
+
trans_text=t_text(input)
|
| 30 |
+
result=reloaded.tf_translate(tf.constant([trans_text]))['text'][0].numpy().decode()
|
| 31 |
+
return result
|
| 32 |
+
|
| 33 |
+
#print(outcome("Please timer ko rokey"))
|
requirements.txt
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
numpy==1.21.6
|
| 2 |
+
pandas==1.3.5
|
| 3 |
+
tensorflow==2.10.1
|
| 4 |
+
tensorflow-text==2.10.0
|
| 5 |
+
Metaphone==0.6
|
| 6 |
+
uvicorn==0.21.1
|
| 7 |
+
fastapi==0.95.0
|
translator/fingerprint.pb
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:4e9da40e2079e447cdbf758c243b6d00b5405441658469b27a0c168c85616d7e
|
| 3 |
+
size 55
|
translator/saved_model.pb
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:b326662c92d9f89da221eae5f48ea82df9257910b8be95d4281637baef13c1f2
|
| 3 |
+
size 1812293
|
translator/variables/variables.data-00000-of-00001
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:35147a7a5d4f859861bd81932110eb97c97eb50a8582cc9ed5f74d60ccbf2b09
|
| 3 |
+
size 191512903
|
translator/variables/variables.index
ADDED
|
Binary file (1.25 kB). View file
|
|
|
vocab_data.pkl
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:2020891aea7517ed34d5459060ad8935cceb77e1b7a58f833725c38422e0798e
|
| 3 |
+
size 1768199
|