UpendraAI commited on
Commit
9d74e47
·
verified ·
1 Parent(s): 3d95dfa

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +52 -0
app.py ADDED
@@ -0,0 +1,52 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import pandas as pd
3
+ from sklearn.feature_extraction.text import TfidfVectorizer
4
+ from sklearn.linear_model import LogisticRegression
5
+ from sklearn.preprocessing import LabelEncoder
6
+ from imblearn.over_sampling import RandomOverSampler
7
+ from sklearn.model_selection import train_test_split
8
+
9
+ @st.cache_data
10
+ def load_data():
11
+ df = pd.read_csv("SushasanSampleData.csv", encoding='utf-8')
12
+ df = df.drop(columns=['ulbName', 'wardName'])
13
+ df['applicationId'] = df['applicationId'].astype(str)
14
+ df['applicationSubCategoryName'] = df['applicationSubCategoryName'].fillna("अन्य")
15
+ return df
16
+
17
+ @st.cache_resource
18
+ def train_model(df):
19
+ tfidf = TfidfVectorizer(max_features=5000)
20
+ X = tfidf.fit_transform(df['applicationDetail'])
21
+
22
+ label_encoder = LabelEncoder()
23
+ y = label_encoder.fit_transform(df['applicationCategoryName'])
24
+
25
+ ros = RandomOverSampler(random_state=42)
26
+ X_resampled, y_resampled = ros.fit_resample(X, y)
27
+
28
+ X_train, X_test, y_train, y_test = train_test_split(X_resampled, y_resampled, test_size=0.2, random_state=42)
29
+
30
+ model = LogisticRegression(max_iter=1000)
31
+ model.fit(X_train, y_train)
32
+
33
+ return model, tfidf, label_encoder
34
+
35
+ # Load and train
36
+ df = load_data()
37
+ model, tfidf, label_encoder = train_model(df)
38
+
39
+ # UI
40
+ st.title("🧾 Hindi Application Category Classifier")
41
+ st.markdown("Enter a grievance or demand in Hindi. The model will predict whether it is a **मांग** (Demand) or a **शिकायत** (Complaint).")
42
+
43
+ user_input = st.text_area("✍️ Application Detail", "")
44
+
45
+ if st.button("🔍 Predict Category"):
46
+ if user_input.strip() == "":
47
+ st.warning("Please enter some text.")
48
+ else:
49
+ input_vector = tfidf.transform([user_input])
50
+ prediction = model.predict(input_vector)
51
+ label = label_encoder.inverse_transform(prediction)[0]
52
+ st.success(f"🧠 Predicted Category: **{label}**")