File size: 2,311 Bytes
76c123c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
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)")