ElifSB's picture
Upload 3 files
76c123c verified
Raw
History Blame Contribute Delete
2.31 kB
import streamlit as st
import tensorflow as tf
import pickle
import numpy as np
import neattext.functions as nfx
# 1. Page Configuration
st.set_page_config(page_title="AI Language Identifier", page_icon="🌍", layout="centered")
# 2. Load Models and Necessary Files
@st.cache_resource
def load_models():
# Ensure these files are in the same directory on Hugging Face Space
model = tf.keras.models.load_model("dil_tespit_modeli.keras")
with open("dil_vektorlestirici.pkl", "rb") as f:
vectorizer = pickle.load(f)
# Original training labels
languages = ['Arabic', 'Danish', 'Dutch', 'English', 'French', 'German', 'Greek', 'Hindi', 'Italian', 'Kannada', 'Malayalam', 'Portuguese', 'Russian', 'Spanish', 'Swedish', 'Tamil', 'Turkish']
return model, vectorizer, languages
model, vectorizer, languages = load_models()
# 3. UI Design
st.title("🌍 Advanced Language Identification System")
st.markdown("""
### Deep Learning Powered NLP Model
Enter any text below, and the AI will determine its language with high precision.
""")
# Text input area
user_input = st.text_area("Input Text for Analysis:", placeholder="e.g., Artificial Intelligence is transforming the world.", height=150)
# Detection Logic
if st.button("Detect Language"):
if user_input.strip():
with st.spinner('Analyzing patterns...'):
# Preprocessing
cleaned = nfx.remove_special_characters(user_input)
cleaned = nfx.remove_numbers(cleaned).lower()
# Vectorization
vectorized = vectorizer.transform([cleaned]).toarray()
# Prediction
prediction = model.predict(vectorized, verbose=0)
lang_index = np.argmax(prediction)
confidence = np.max(prediction) * 100
detected_lang = languages[lang_index]
# Display Results
st.success(f"### Detected Language: {detected_lang}")
st.progress(int(confidence))
st.info(f"**Confidence Score:** {confidence:.2f}%")
else:
st.warning("Please enter some text first to analyze.")
# Footer
st.markdown("---")
st.caption("Data Science Project | Deep Learning & Advanced NLP (ANN Model)")