File size: 1,166 Bytes
217f6db
820d22d
62e6a56
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
820d22d
62e6a56
 
 
 
 
 
820d22d
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
import gradio as gr
import pandas as pd
import os

# مسیر CSV
csv_path = "stoic_quotes_full.csv"

# بارگذاری داده‌ها
def load_data():
    if not os.path.exists(csv_path):
        return None
    return pd.read_csv(csv_path)

# تحلیل متن
def analyze_text(text):
    df = load_data()
    if df is None:
        return "❌ دیتابیس پیدا نشد."
    
    text = text.strip().lower()
    if not text:
        return "⚠️ لطفاً یک متن وارد کنید."
    
    # جستجو در نقل‌قول‌ها
    match = df[df['quote'].str.lower() == text]
    
    if not match.empty:
        philosopher = match.iloc[0]['philosopher']
        return f"✅ این جمله از {philosopher} است."
    else:
        return "❌ این جمله در دیتاست وجود ندارد."

# رابط کاربری
with gr.Blocks() as demo:
    gr.Markdown("## متن فلسفی را وارد کنید")
    text_input = gr.Textbox(label="متن")
    analyze_btn = gr.Button("تحلیل")
    output = gr.Textbox(label="نتیجه")
    
    analyze_btn.click(analyze_text, inputs=text_input, outputs=output)

demo.launch()