Spaces:
Sleeping
Sleeping
Commit
·
5372fcc
1
Parent(s):
19f568a
initial commit
Browse files- main.py +53 -0
- model.py +40 -0
- requirements.txt +3 -0
- trained_pipeline-0.1.0.pkl +3 -0
main.py
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
import json
|
| 3 |
+
import requests
|
| 4 |
+
from model import predict_pipeline
|
| 5 |
+
|
| 6 |
+
st.title("Language Detection Model")
|
| 7 |
+
st.write("")
|
| 8 |
+
st.write("Supported Languages:")
|
| 9 |
+
|
| 10 |
+
col1, col2, col3, col4 = st.columns(4)
|
| 11 |
+
with col1:
|
| 12 |
+
st.markdown("- Arabic")
|
| 13 |
+
st.markdown("- Danish")
|
| 14 |
+
st.markdown("- Dutch")
|
| 15 |
+
st.markdown("- English")
|
| 16 |
+
st.markdown("- French")
|
| 17 |
+
|
| 18 |
+
|
| 19 |
+
with col2:
|
| 20 |
+
st.markdown("- German")
|
| 21 |
+
st.markdown("- Greek")
|
| 22 |
+
st.markdown("- Hindi")
|
| 23 |
+
st.markdown("- Italian")
|
| 24 |
+
|
| 25 |
+
with col3:
|
| 26 |
+
st.markdown("- Kannada")
|
| 27 |
+
st.markdown("- Malayalam")
|
| 28 |
+
st.markdown("- Portugeese")
|
| 29 |
+
st.markdown("- Russian")
|
| 30 |
+
|
| 31 |
+
with col4:
|
| 32 |
+
st.markdown("- Spanish")
|
| 33 |
+
st.markdown("- Sweedish")
|
| 34 |
+
st.markdown("- Tamil")
|
| 35 |
+
st.markdown("- Turkish")
|
| 36 |
+
|
| 37 |
+
st.markdown('''
|
| 38 |
+
<style>
|
| 39 |
+
[data-testid="stMarkdownContainer"] ul{
|
| 40 |
+
list-style-position: inside;
|
| 41 |
+
}
|
| 42 |
+
</style>
|
| 43 |
+
''', unsafe_allow_html=True)
|
| 44 |
+
|
| 45 |
+
|
| 46 |
+
title = st.text_input('Input text', 'Please enter the text here')
|
| 47 |
+
st.write('The current text is', title)
|
| 48 |
+
|
| 49 |
+
inputs = {"text": title}
|
| 50 |
+
|
| 51 |
+
if st.button("Detect Language"):
|
| 52 |
+
language = predict_pipeline(json.dumps(inputs))
|
| 53 |
+
st.write(f'Language: {language}')
|
model.py
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import pickle
|
| 2 |
+
import re
|
| 3 |
+
from pathlib import Path
|
| 4 |
+
|
| 5 |
+
__version__ = "0.1.0"
|
| 6 |
+
|
| 7 |
+
BASE_DIR = Path(__file__).resolve(strict=True).parent
|
| 8 |
+
|
| 9 |
+
|
| 10 |
+
with open(f"{BASE_DIR}/trained_pipeline-{__version__}.pkl", "rb") as f:
|
| 11 |
+
model = pickle.load(f)
|
| 12 |
+
|
| 13 |
+
|
| 14 |
+
classes = [
|
| 15 |
+
"Arabic",
|
| 16 |
+
"Danish",
|
| 17 |
+
"Dutch",
|
| 18 |
+
"English",
|
| 19 |
+
"French",
|
| 20 |
+
"German",
|
| 21 |
+
"Greek",
|
| 22 |
+
"Hindi",
|
| 23 |
+
"Italian",
|
| 24 |
+
"Kannada",
|
| 25 |
+
"Malayalam",
|
| 26 |
+
"Portugeese",
|
| 27 |
+
"Russian",
|
| 28 |
+
"Spanish",
|
| 29 |
+
"Sweedish",
|
| 30 |
+
"Tamil",
|
| 31 |
+
"Turkish",
|
| 32 |
+
]
|
| 33 |
+
|
| 34 |
+
|
| 35 |
+
def predict_pipeline(text):
|
| 36 |
+
text = re.sub(r'[!@#$(),\n"%^*?\:;~`0-9]', " ", text)
|
| 37 |
+
text = re.sub(r"[[]]", " ", text)
|
| 38 |
+
text = text.lower()
|
| 39 |
+
pred = model.predict([text])
|
| 40 |
+
return classes[pred[0]]
|
requirements.txt
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
streamlit==1.22.0
|
| 2 |
+
requests==2.30.0
|
| 3 |
+
scikit-learn==1.2.2
|
trained_pipeline-0.1.0.pkl
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:0894da01a3536140440401b6623cb33fd13d6e9791129bf5830d3e0b57a22d16
|
| 3 |
+
size 9982945
|