M3zzYL commited on
Commit
2789db4
·
verified ·
1 Parent(s): 6cf4eab

Upload 3 files

Browse files
Files changed (3) hide show
  1. app.py +95 -0
  2. faith_library_final_v56.json +0 -0
  3. requirements.txt +5 -0
app.py ADDED
@@ -0,0 +1,95 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import sqlite3
3
+ import pandas as pd
4
+ import plotly.express as px
5
+ import random
6
+ import json
7
+ import os
8
+ from datetime import datetime
9
+ from transformers import pipeline
10
+
11
+ # --- DB & MODEL SETUP ---
12
+ def init_db():
13
+ conn = sqlite3.connect('faithpath.db')
14
+ conn.execute('CREATE TABLE IF NOT EXISTS journal_entries (id INTEGER PRIMARY KEY AUTOINCREMENT, date TEXT, entry_text TEXT, detected_emotion TEXT, mission_source TEXT, mission_text TEXT, city TEXT)')
15
+ conn.commit(); conn.close()
16
+
17
+ init_db()
18
+ sentiment_analyzer = pipeline('sentiment-analysis', model='savasy/bert-base-turkish-sentiment-cased')
19
+
20
+ with open('faith_library_final_v56.json', 'r', encoding='utf-8') as f:
21
+ faith_library = json.load(f)
22
+
23
+ def semantic_engine(metin):
24
+ t = metin.lower()
25
+ logic = {
26
+ 'öfke_ve_gerginlik': ['nevrim döndü', 'parlamamak', 'zor tutuyorum', 'damarıma bas', 'tepemin tasını'],
27
+ 'şükran_ve_minnet': ['secde-i şükran', 'hamdolsun', 'minnettarım', 'allah bin bereket'],
28
+ 'sabır_ve_metanet': ['bağrıma taş bastım', 'isyan etmeksizin', 'dişini sıkıp', 'sabır taşı'],
29
+ 'cömertlik_ve_paylaşma': ['rızkı paylaştıkça', 'ihtiyacı olana', 'infak etmek', 'sadaka']
30
+ }
31
+ for cat, words in logic.items():
32
+ if any(w in t for w in words): return cat, random.choice(faith_library.get(cat, []))
33
+ res = sentiment_analyzer(metin)[0]
34
+ cat = 'mutluluk_ve_huzur' if res['label'] == 'positive' else 'hüzün_ve_keder'
35
+ return cat, random.choice(faith_library.get(cat, []))
36
+
37
+ def process_user(text):
38
+ if len(text.strip()) < 10: return "<div style='padding:20px; background:#7f1d1d; color:white; border-radius:10px;'>Hata: Analiz için daha detaylı bir cümle yazmalısınız.</div>"
39
+ cat, mission = semantic_engine(text)
40
+ conn = sqlite3.connect('faithpath.db')
41
+ conn.execute('INSERT INTO journal_entries (date, entry_text, detected_emotion, mission_source, mission_text, city) VALUES (?,?,?,?,?,?)',
42
+ (datetime.now().strftime('%Y-%m-%d %H:%M:%S'), text, cat, mission['kaynak'], mission['metin'], 'Belirtilmemiş'))
43
+ conn.commit(); conn.close()
44
+
45
+ return f"""<div style='padding:30px; border-radius:20px; background:#0f172a; border:2px solid #10b981; color:white; font-family:sans-serif;'>
46
+ <h2 style='color:#10b981; text-align:center; margin-top:0;'>🕊️ Manevi Rehberlik</h2>
47
+ <div style='background:#1e293b; padding:20px; border-radius:15px; margin:20px 0; border-left:6px solid #3b82f6;'>
48
+ <p style='color:#94a3b8; font-size:0.8em; text-transform:uppercase; margin-bottom:5px;'>Sistem Analizi: {cat.replace('_',' ').title()}</p>
49
+ <p style='font-size:1.3em; font-style:italic; line-height:1.5;'>"{mission['metin']}"</p>
50
+ <p style='text-align:right; color:#10b981; font-weight:bold;'>— {mission['kaynak']}</p>
51
+ </div>
52
+ <div style='background:#064e3b; padding:20px; border-radius:15px; border-left:6px solid #fbbf24;'>
53
+ <strong style='color:#fbbf24; display:block; margin-bottom:8px; font-size:1.1em;'>🎯 Bugünün Kalp Görevi:</strong>
54
+ <p style='font-size:1.1em; line-height:1.4;'>{mission.get('rehber_mesaji', 'Ailenizle vakit geçirin.')}</p>
55
+ </div>
56
+ </div>"""
57
+
58
+ def get_admin(pwd):
59
+ if pwd != 'Enes.13112006': return gr.update(visible=False), None, None, "### Hata: Yetkisiz Erişim"
60
+ conn = sqlite3.connect('faithpath.db'); df = pd.read_sql_query('SELECT * FROM journal_entries ORDER BY id DESC', conn); conn.close()
61
+ if df.empty: return gr.update(visible=True), None, None, "Veri yok."
62
+
63
+ # Plot 1: Sentiment Distribution
64
+ fig_pie = px.pie(df, names='detected_emotion', title='Genel Duygu Dağılımı', template='plotly_dark', hole=.4)
65
+
66
+ # Plot 2: Time Trend (DD/MM/YYYY)
67
+ df['date_dt'] = pd.to_datetime(df['date'])
68
+ trend_df = df.groupby(df['date_dt'].dt.date).size().reset_index(name='Sayi')
69
+ fig_line = px.line(trend_df, x='date_dt', y='Sayi', title='Kayıt Trendi', template='plotly_dark', markers=True)
70
+ fig_line.update_xaxes(tickformat="%d/%m/%Y")
71
+
72
+ table = df[['date', 'entry_text', 'detected_emotion']].to_html(classes='table table-dark table-hover', index=False)
73
+ return gr.update(visible=True), fig_pie, fig_line, f"### Toplam Kayıt: {len(df)}\n{table}"
74
+
75
+ # --- UI DESIGN ---
76
+ with gr.Blocks(theme=gr.themes.Soft(), css='.gradio-container {background-color: #0f172a}') as demo:
77
+ gr.Markdown("<h1 style='text-align:center; color:#10b981;'>🕊️ FaithPath Professional v5.8.8</h1>")
78
+ with gr.Tabs():
79
+ with gr.Tab('🕊️ Rehberlik Asistanı'):
80
+ with gr.Row():
81
+ with gr.Column(scale=2):
82
+ txt = gr.Textbox(label='Bugün ailenizle ilgili neler yaşadınız?', placeholder='Duygularınızı buraya yazın...', lines=10)
83
+ btn = gr.Button('Analiz Et ve Rehberlik Al', variant='primary')
84
+ with gr.Column(scale=3): out = gr.HTML()
85
+ btn.click(process_user, [txt], out)
86
+ with gr.Tab('📊 Yönetici Paneli'):
87
+ with gr.Row():
88
+ pwd = gr.Textbox(label='Yönetici Şifresi', type='password'); lbtn = gr.Button('Sisteme Giriş')
89
+ with gr.Column(visible=False) as zone:
90
+ with gr.Row():
91
+ plt1 = gr.Plot(); plt2 = gr.Plot()
92
+ stats = gr.HTML()
93
+ lbtn.click(get_admin, pwd, [zone, plt1, plt2, stats])
94
+ gr.Markdown("<center style='color:#64748b; margin-top:20px;'>Enes YILMAZ - Karabük University | Time Analysis & Simplified UI</center>")
95
+ demo.launch()
faith_library_final_v56.json ADDED
The diff for this file is too large to render. See raw diff
 
requirements.txt ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
 
1
+ gradio
2
+ pandas
3
+ plotly
4
+ transformers
5
+ torch