|
|
import gradio as gr |
|
|
import pandas as pd |
|
|
import os |
|
|
|
|
|
|
|
|
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() |
|
|
|