| |
| |
| |
|
|
| |
| |
|
|
| |
| |
| |
|
|
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
|
|
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
|
|
| |
| |
| |
| |
| |
|
|
| |
| |
|
|
| |
| |
|
|
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| import streamlit as st |
| from transformers import pipeline |
| import re |
|
|
| |
| classifier = pipeline("text-classification", model="Mpavan45/Telugu_Sentimental_Analysis") |
|
|
| |
| labels = ["neutral", "positive", "negative"] |
| emojis = {"positive": "🤗", "negative": "😔", "neutral": "😐"} |
|
|
| |
| st.markdown(""" |
| <style> |
| .stApp { |
| background-image: url('https://cdn-uploads.huggingface.co/production/uploads/675fab3a2d0851e23d23cad3/_YKXYHCbjM44ubGwnAKeQ.jpeg'); |
| background-size: cover; |
| background-position: center; |
| background-repeat: no-repeat; |
| background-attachment: fixed; |
| font-family: 'Segoe UI', sans-serif; |
| } |
| |
| .radium-title { |
| font-size: 30px; |
| text-align: center; |
| color: #fff; |
| padding: 10px; |
| border-radius: 10px; |
| background: linear-gradient(90deg, #8E2DE2, #4A00E0); |
| box-shadow: 0 0 20px #8E2DE2, 0 0 30px #4A00E0; |
| margin-bottom: 20px; |
| } |
| |
| .radium-label { |
| font-size: 28px; |
| font-weight: bold; |
| color: white; |
| padding: 10px 20px; |
| border-radius: 12px; |
| background: linear-gradient(90deg, #7F00FF, #E100FF); |
| display: inline-block; |
| margin-top: 20px; |
| } |
| |
| .radium-button > button { |
| font-size: 20px !important; |
| font-weight: bold !important; |
| color: white !important; |
| border: none !important; |
| padding: 12px 28px !important; |
| border-radius: 12px !important; |
| background: linear-gradient(90deg, #8E2DE2, #4A00E0) !important; |
| box-shadow: 0 0 10px #8E2DE2, 0 0 20px #4A00E0; |
| transition: all 0.3s ease-in-out; |
| } |
| |
| .radium-button > button:hover { |
| box-shadow: 0 0 20px #fff, 0 0 30px #8E2DE2; |
| transform: scale(1.05); |
| } |
| |
| textarea { |
| font-size: 20px !important; |
| line-height: 1.5 !important; |
| padding: 10px !important; |
| } |
| |
| .example-box { |
| background-color: rgba(255, 255, 255, 0.1); |
| color: white; |
| padding: 10px 15px; |
| border-radius: 10px; |
| font-size: 15px; |
| margin-bottom: 10px; |
| } |
| </style> |
| """, unsafe_allow_html=True) |
|
|
| |
| st.markdown('<div class="radium-title">Telugu Sentiment Analysis</div>', unsafe_allow_html=True) |
|
|
| |
| def is_mostly_telugu(text): |
| if not text.strip(): |
| return False |
| telugu_pattern = r'[\u0C00-\u0C7F]' |
| allowed_pattern = r'[a-zA-Z0-9\s.,!?]' |
| telugu_chars = len(re.findall(telugu_pattern, text)) |
| allowed_chars = len(re.findall(allowed_pattern, text)) |
| total_chars = len(text) |
| telugu_ratio = telugu_chars / total_chars if total_chars > 0 else 0 |
| valid_chars = telugu_chars + allowed_chars == total_chars |
| return telugu_ratio >= 0.7 and valid_chars |
|
|
| def clean_input(text): |
| cleaned_text = re.sub(r'[^a-zA-Z0-9\u0C00-\u0C7F\s?.!]', ' ', text) |
| cleaned_text = re.sub(r'([?.!])(?![?.!]\s|$)', '', cleaned_text) |
| return ' '.join(cleaned_text.split()) |
|
|
| |
| st.markdown("### 📝 You can only enter pure Telugu text. Try one of the examples below if you'd like:") |
| st.markdown('<div class="example-box">ఆమెతో మాట్లాడిన తర్వాత నా మనసు తేలికపడింది.</div>', unsafe_allow_html=True) |
| st.markdown('<div class="example-box">ఈ రోజు నేను చాలా నిరాశతో ఉన్నాను. ఏది కూడా సరిగ్గా జరగడం లేదు.</div>', unsafe_allow_html=True) |
|
|
| |
| user_input = st.text_area(" ", height=180, key="input_box") |
|
|
| |
| col1, col2 = st.columns(2) |
|
|
| with col1: |
| if st.markdown('<div class="radium-button">', unsafe_allow_html=True): |
| if st.button("🔮 Predict"): |
| if not user_input.strip(): |
| st.warning("Please enter some Telugu text.") |
| else: |
| cleaned = clean_input(user_input) |
| if not is_mostly_telugu(cleaned): |
| st.error("Please enter text primarily in Telugu script.") |
| else: |
| result = classifier(cleaned)[0] |
| label = result['label'] |
| try: |
| index = int(label.split('_')[-1]) |
| sentiment = labels[index] |
| except (ValueError, IndexError): |
| sentiment = label.lower() if label.lower() in labels else "neutral" |
|
|
| sentiment_display = f'{sentiment.capitalize()} {emojis.get(sentiment, "")}' |
| st.markdown(f'<div class="radium-label">{sentiment_display}</div>', unsafe_allow_html=True) |
|
|
|
|
| |
| with col2: |
| if st.markdown('<div class="radium-button">', unsafe_allow_html=True): |
| if st.button("🧹 Clear"): |
| st.session_state.input_box = "" |
|
|