M3zzYL commited on
Commit
a2680b7
·
verified ·
1 Parent(s): 0e6711e

Delete app.py

Browse files
Files changed (1) hide show
  1. app.py +0 -144
app.py DELETED
@@ -1,144 +0,0 @@
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
- # --- DATABASE INITIALIZATION ---
12
- def init_db():
13
- conn = sqlite3.connect('faithpath.db')
14
- cursor = conn.cursor()
15
- cursor.execute('''
16
- CREATE TABLE IF NOT EXISTS journal_entries (
17
- id INTEGER PRIMARY KEY AUTOINCREMENT,
18
- date TEXT,
19
- entry_text TEXT,
20
- detected_emotion TEXT,
21
- mission_source TEXT,
22
- mission_text TEXT,
23
- city TEXT
24
- )
25
- ''')
26
- conn.commit()
27
- conn.close()
28
-
29
- init_db()
30
-
31
- # --- MODEL & LIBRARY LOADING ---
32
- sentiment_analyzer = pipeline('sentiment-analysis', model='savasy/bert-base-turkish-sentiment-cased')
33
-
34
- if os.path.exists('faith_library_final_v56.json'):
35
- with open('faith_library_final_v56.json', 'r', encoding='utf-8') as f:
36
- faith_library = json.load(f)
37
- else:
38
- faith_library = {}
39
-
40
- # --- CORE ENGINE ---
41
- def semantic_bridge_engine(metin):
42
- text_lower = metin.lower()
43
- exclusive_logic = {
44
- 'öfke_ve_gerginlik': ['sabrımın son kertesindeyim', 'bendini aşan', 'yanardağ gibiyim', 'tepemin tasını', 'damarıma bas', 'nevrim döndü', 'parlamamak', 'zor tutuyorum'],
45
- 'şükran_ve_minnet': ['secde-i şükran', 'selamet kapısı', 'bereketli lokma', 'nimetlerin kadrini', 'hamd etsek az', 'minnettarım', 'şükür secdesine', 'allah bin bereket', 'halimize bin şükür'],
46
- 'sabır_ve_metanet': ['bağrıma taş basıp', 'bağrıma taş bastım', 'isyan etmeksizin', 'metanetimi koruyarak', 'dişini sıkıp', 'sıramı bekleyerek', 'zamanın değirmeninde', 'sabır taşı'],
47
- 'cömertlik_ve_paylaşma': ['rızkı paylaştıkça', 'ihtiyacı olana', 'gönlümüzü açtık', 'infak etmek', 'sadaka vermek', 'ikramda bulunmak']
48
- }
49
- for cat, words in exclusive_logic.items():
50
- if any(w in text_lower for w in words):
51
- return cat, random.choice(faith_library.get(cat, []))
52
-
53
- bert_res = sentiment_analyzer(metin)[0]
54
- cat = 'mutluluk_ve_huzur' if bert_res['label'] == 'positive' else 'hüzün_ve_keder'
55
- return cat, random.choice(faith_library.get(cat, []))
56
-
57
- # --- UI FUNCTIONS ---
58
- def process_entry_user(text):
59
- if len(text.strip()) < 10:
60
- return "<div style='padding:20px; background:#7f1d1d; color:white; border-radius:10px;'>Hata: Analiz için en az bir cümle yazmalısınız.</div>"
61
-
62
- cat, mission = semantic_bridge_engine(text)
63
- cat_title = cat.replace('_', ' ').title()
64
-
65
- conn = sqlite3.connect('faithpath.db')
66
- cursor = conn.cursor()
67
- cursor.execute('''
68
- INSERT INTO journal_entries (date, entry_text, detected_emotion, mission_source, mission_text, city)
69
- VALUES (?, ?, ?, ?, ?, ?)
70
- ''', (datetime.now().strftime('%Y-%m-%d %H:%M:%S'), text, cat, mission['kaynak'], mission['metin'], 'Web Kullanicisi'))
71
- conn.commit()
72
- conn.close()
73
-
74
- # COLOR FIX: YELLOW CHANGED TO SAGE GREEN/BLUE
75
- return f"""
76
- <div style='padding: 25px; border-radius: 15px; background-color: #0f172a; border: 2px solid #10b981; color: white;'>
77
- <h2 style='color: #10b981; text-align: center;'>FaithPath Manevi Rehberlik</h2>
78
- <div style='background: #1e293b; padding: 15px; border-radius: 10px; margin: 15px 0;'>
79
- <p style='font-size: 1.2em; font-style: italic;'>"{mission['metin']}"</p>
80
- <p style='text-align: right; color: #10b981;'>- {mission['kaynak']}</p>
81
- </div>
82
- <div style='background: #064e3b; color: #ecfdf5; padding: 15px; border-radius: 10px; border-left: 5px solid #10b981;'>
83
- <strong>Bugunun Kalp Gorevi:</strong><br>{mission.get('rehber_mesaji', 'Ailenizle vakit gecirin.')}
84
- </div>
85
- </div>
86
- """
87
-
88
- # --- ADMIN & ANALYTICS FUNCTIONS ---
89
- def get_admin_content(password):
90
- if password != 'Enes.13112006':
91
- return gr.update(visible=False), None, None, '### Hata: Gecersiz Sifre'
92
-
93
- conn = sqlite3.connect('faithpath.db')
94
- df = pd.read_sql_query('SELECT * FROM journal_entries', conn)
95
- conn.close()
96
-
97
- if df.empty:
98
- return gr.update(visible=True), None, None, '### Sistemde henüz veri bulunmuyor.'
99
-
100
- df['Duygu'] = df['detected_emotion'].str.replace('_', ' ').str.title()
101
-
102
- # Multi-plot generation
103
- fig_pie = px.pie(df, names='Duygu', title='Duygu Dagilimi', hole=.3, template='plotly_dark')
104
-
105
- df['date_only'] = pd.to_datetime(df['date']).dt.date
106
- trend_data = df.groupby('date_only').size().reset_index(name='Kayit Sayisi')
107
- fig_trend = px.line(trend_data, x='date_only', y='Kayit Sayisi', title='Gunluk Kayit Trendi', template='plotly_dark')
108
-
109
- stats_msg = f'### Sistem Istatistikleri\n- Toplam Kayit: {len(df)}\n- Son Islem: {df['date\'].iloc[-1]}'
110
-
111
- return gr.update(visible=True), fig_pie, fig_trend, stats_msg
112
-
113
- # --- GRADIO UI ---
114
- with gr.Blocks(theme=gr.themes.Soft(), css='.gradio-container {background-color: #0f172a}') as demo:
115
- gr.Markdown('# FaithPath Professional v5.8.2')
116
-
117
- with gr.Tabs():
118
- with gr.Tab('Asistan'):
119
- txt_input = gr.Textbox(label='Bugun ailenizle ilgili neler yasadiniz?', lines=6)
120
- submit_btn = gr.Button('Analiz Et', variant='primary')
121
- html_out = gr.HTML()
122
- submit_btn.click(process_entry_user, txt_input, html_out)
123
-
124
- with gr.Tab('Yonetici Paneli'):
125
- admin_pwd = gr.Textbox(label='Sifre', type='password')
126
- login_btn = gr.Button('Giris Yap')
127
-
128
- stats_area = gr.Markdown()
129
-
130
- with gr.Column(visible=False) as admin_zone:
131
- with gr.Row():
132
- plot_pie = gr.Plot(label='Pasta Grafigi')
133
- plot_trend = gr.Plot(label='Trend Grafigi')
134
-
135
- with gr.Row():
136
- export_btn = gr.Button('CSV Aktar')
137
- reset_btn = gr.Button('Sifirla', variant='stop')
138
- export_f = gr.File(label='Dosya')
139
-
140
- login_btn.click(get_admin_content, admin_pwd, [admin_zone, plot_pie, plot_trend, stats_area])
141
-
142
- gr.Markdown('<center>Enes YILMAZ - Karabuk University</center>')
143
-
144
- demo.launch()