M3zzYL commited on
Commit
06cbb4c
·
verified ·
1 Parent(s): bbc06ba

Delete app.py

Browse files
Files changed (1) hide show
  1. app.py +0 -84
app.py DELETED
@@ -1,84 +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
- # --- 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, "### 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, "Veri yok."
62
- fig = px.pie(df, names='detected_emotion', title='Duygu Dağılımı', template='plotly_dark', hole=.4)
63
- table = df[['date', 'entry_text', 'detected_emotion']].to_html(classes='table table-dark table-hover', index=False)
64
- return gr.update(visible=True), fig, f"### Toplam Kayıt: {len(df)}\n{table}"
65
-
66
- # --- UI DESIGN ---
67
- with gr.Blocks(theme=gr.themes.Soft(), css='.gradio-container {background-color: #0f172a}') as demo:
68
- gr.Markdown("<h1 style='text-align:center; color:#10b981;'>🕊️ FaithPath Professional v5.8.7</h1>")
69
- with gr.Tabs():
70
- with gr.Tab('🕊️ Rehberlik Asistanı'):
71
- with gr.Row():
72
- with gr.Column(scale=2):
73
- txt = gr.Textbox(label='Bugün ailenizle ilgili neler yaşadınız?', placeholder='Duygularınızı buraya yazın...', lines=10)
74
- btn = gr.Button('Analiz Et ve Rehberlik Al', variant='primary')
75
- with gr.Column(scale=3): out = gr.HTML()
76
- btn.click(process_user, [txt], out)
77
- with gr.Tab('📊 Yönetici Paneli'):
78
- with gr.Row():
79
- pwd = gr.Textbox(label='Yönetici Şifresi', type='password'); lbtn = gr.Button('Sisteme Giriş')
80
- with gr.Column(visible=False) as zone:
81
- plt = gr.Plot(); stats = gr.HTML()
82
- lbtn.click(get_admin, pwd, [zone, plt, stats])
83
- gr.Markdown("<center style='color:#64748b; margin-top:20px;'>Enes YILMAZ - Karabük University | No-City Simple UI</center>")
84
- demo.launch()