ESMATUGBA commited on
Commit
9677bb6
·
verified ·
1 Parent(s): 4111e03

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -13
app.py CHANGED
@@ -9,7 +9,7 @@ import os
9
  import nltk
10
  import plotly.graph_objects as go
11
 
12
- # --- NLTK / TEXTBLOB HATA ÇÖZÜCÜ (KRİTİK KISIM) ---
13
  @st.cache_resource
14
  def download_nltk_data():
15
  try:
@@ -17,7 +17,6 @@ def download_nltk_data():
17
  nltk.download('wordnet')
18
  nltk.download('omw-1.4')
19
  nltk.download('punkt_tab')
20
- # TextBlob'un içsel corpora'sını zorla yükle
21
  from textblob import download_corpora
22
  download_corpora.download_all()
23
  except Exception as e:
@@ -105,43 +104,43 @@ if selected_cat != "":
105
  st.sidebar.info(f"Örnek {i}:")
106
  st.sidebar.code(ex, language=None)
107
 
108
- # --- ANA SAYFA ---
109
- st.title("📰 Multidisciplinary News Classifier")
110
  st.markdown("---")
111
 
112
  user_input = st.text_area("News Headline / Haber Başlığı:", height=150, placeholder="Sol taraftan bir örnek kopyalayıp buraya yapıştırın...")
113
 
114
  if st.button("Predict / Tahmin Et"):
115
  if user_input.strip() != "":
116
- with st.spinner('Analiz ediliyor...'):
117
  # 1. Tahmin
118
  category, confidence, all_probs = predict_news(user_input)
119
 
120
- # 2. Çeviri (Hatasız Yöntem)
121
  try:
122
  translated = str(TextBlob(user_input).translate(from_lang='en', to='tr'))
123
  except:
124
- translated = "Çeviri şu an yapılamıyor (Bağlantı hatası)."
125
 
126
  st.balloons()
127
 
128
  # 3. Haber ve Çeviri Gösterimi
129
- st.info(f"**Original:** {user_input}\n\n**Türkçe Çeviri:** *{translated}*")
130
  st.markdown("---")
131
 
132
- # 4. Sonuçlar
133
  res_col1, res_col2 = st.columns(2)
134
- res_col1.success(f"**Category / Kategori:**\n### {category}")
135
- res_col2.warning(f"**Confidence / Güven:**\n### %{confidence*100:.2f}")
136
 
137
  # 5. Mavi Grafik
138
  labels = le.classes_
139
  fig = go.Figure(go.Bar(
140
  x=all_probs, y=labels, orientation='h',
141
- marker_color='#1F77B4', # Mavi Renk
142
  text=[f"%{p*100:.1f}" for p in all_probs], textposition='auto'
143
  ))
144
  fig.update_layout(title="Probability Graph / Olasılık Grafiği", height=350)
145
  st.plotly_chart(fig, use_container_width=True)
146
  else:
147
- st.warning("⚠️ Lütfen bir haber başlığı girin!")
 
9
  import nltk
10
  import plotly.graph_objects as go
11
 
12
+ # --- NLTK / TEXTBLOB HATA ÇÖZÜCÜ ---
13
  @st.cache_resource
14
  def download_nltk_data():
15
  try:
 
17
  nltk.download('wordnet')
18
  nltk.download('omw-1.4')
19
  nltk.download('punkt_tab')
 
20
  from textblob import download_corpora
21
  download_corpora.download_all()
22
  except Exception as e:
 
104
  st.sidebar.info(f"Örnek {i}:")
105
  st.sidebar.code(ex, language=None)
106
 
107
+ # --- ANA SAYFA (BAŞLIKLAR GÜNCELLENDİ) ---
108
+ st.title("📰 Multidisciplinary News Classifier / Çok Disiplinli Haber Sınıflandırıcı")
109
  st.markdown("---")
110
 
111
  user_input = st.text_area("News Headline / Haber Başlığı:", height=150, placeholder="Sol taraftan bir örnek kopyalayıp buraya yapıştırın...")
112
 
113
  if st.button("Predict / Tahmin Et"):
114
  if user_input.strip() != "":
115
+ with st.spinner('Analiz ediliyor / Processing...'):
116
  # 1. Tahmin
117
  category, confidence, all_probs = predict_news(user_input)
118
 
119
+ # 2. Çeviri
120
  try:
121
  translated = str(TextBlob(user_input).translate(from_lang='en', to='tr'))
122
  except:
123
+ translated = "Çeviri şu an yapılamıyor."
124
 
125
  st.balloons()
126
 
127
  # 3. Haber ve Çeviri Gösterimi
128
+ st.info(f"**Original / Orijinal:** {user_input}\n\n**Türkçe Çeviri / Turkish Translation:** *{translated}*")
129
  st.markdown("---")
130
 
131
+ # 4. Sonuçlar (Başlıklar Türkçe-İngilizce yapıldı)
132
  res_col1, res_col2 = st.columns(2)
133
+ res_col1.success(f"**Predicted Category / Tahmin Edilen Kategori:**\n### {category}")
134
+ res_col2.warning(f"**Confidence Score / Güven Oranı:**\n### %{confidence*100:.2f}")
135
 
136
  # 5. Mavi Grafik
137
  labels = le.classes_
138
  fig = go.Figure(go.Bar(
139
  x=all_probs, y=labels, orientation='h',
140
+ marker_color='#1F77B4',
141
  text=[f"%{p*100:.1f}" for p in all_probs], textposition='auto'
142
  ))
143
  fig.update_layout(title="Probability Graph / Olasılık Grafiği", height=350)
144
  st.plotly_chart(fig, use_container_width=True)
145
  else:
146
+ st.warning("⚠️ Lütfen bir haber başlığı girin! / Please enter a headline!")