CoolFace
Apppublic

GehadNasser/Analysis_Chat

sourceHugging Faceupdated 1y agoView on Hugging Face
0likes
app.py119 linesDownload Raw Back to root
1import gradio as gr2import google.generativeai as genai3import os4 5# API Key 6genai.configure(api_key=os.environ.get("GOOGLE_API_KEY")) 7 8# Gemini settings9model = genai.GenerativeModel("gemini-2.0-flash-lite")10 11def analyze_conversation(text):12    prompt = f"""13أنت خبير في تحليل المحادثات بين العملاء ومقدمي الخدمات.14 15حلل المحادثة التالية بشكل دقيق، منطقي، وواضح. المطلوب:16- استنتج درجة رضا العميل (منخفضة، متوسطة، عالية) ووضح السبب.17- حدد جميع المشاكل التي ظهرت في المحادثة على شكل نقاط.18- في حالة وجود مشكلة، حدد من هو المسؤول الحقيقي عنها بدقة، **ولا تُحمّل مقدم الخدمة المسؤولية إن لم يكن سببًا مباشرًا في المشكلة**.19- لا تُجامل الطرفين، ركّز على الحقيقة بناءً على تسلسل الحوار فقط.20 21صيغة التحليل المطلوبة:22- ✅ نسبة رضا العميل: ...23- ✅ المشاكل (إن وُجدت): ...24- ✅ المسؤول عن المشكلة (إن وُجدت): ...25 26نص المحادثة:27{text}28    """29    try:30        response = model.generate_content(prompt)31        result = ""32        for part in response.parts:33            result += part.text + "\n"34        return result.strip()35    except Exception as e:36        return f"❌ حصل خطأ: {str(e)}"37 38# HTML Title and Logo39custom_header = """40<div id='logo-header'>41    <img src='https://huggingface.co/spaces/GehadNasser/Analysis_Chat/resolve/main/logo.png' 42         style='width: 80px; margin-bottom: 10px;'/>43    44    <h1 style='font-family: Arial, sans-serif; font-size: 30px; margin: 0;'>45        <span style='color: #147E93;'>Service</span><span style='color: #FDBC10;'>Sphere</span>46    </h1>47    48    <p style='color: #147E93; font-size: 18px;'>🗨️ أدخل المحادثة بين العميل وصاحب الخدمة</p>49</div>50"""51 52 53 54# CSS 55custom_css = """56html, body, .gradio-container {57    background-color: white !important;58}59 60/* لتوسيط اللوجو مع النص */61#logo-header {62    display: flex;63    flex-direction: column;64    align-items: center;65    justify-content: center;66}67 68/* نص الإدخال */69textarea {70    background-color: white !important;71    color: #147E93 !important;72    font-size: 16px !important;73    direction: rtl;74}75 76/* الزر */77.custom-btn-service {78    background-color: #147E93 !important;79    color: white !important;80    font-weight: bold;81    border-radius: 8px !important;82    padding: 10px 20px !important;83    font-size: 16px !important;84    border: none !important;85}86 87/* مربعات الإدخال والإخراج */88.gr-box, .gr-input, .gr-textbox {89    border: 2px solid #FDBC10 !important;90    border-radius: 10px !important;91    background-color: #147E93 !important;92    color: white !important;93}94 95/* العناوين فوق المربعات */96.label, .textbox-label label {97    color: #FDBC10 !important;98    font-weight: bold;99    font-size: 16px;100    direction: rtl;101}102"""103 104 105# Gradio106with gr.Blocks(css=custom_css) as demo:107    gr.HTML(custom_header)108 109    with gr.Row():110        with gr.Column():111            chat_input = gr.Textbox(label="📝 نص المحادثة", lines=10, placeholder="أدخل المحادثة هنا...")112        with gr.Column():113            analysis_output = gr.Textbox(label="📋 التحليل", lines=10)114 115    analyze_btn = gr.Button("تحليل المحادثة", elem_classes=["custom-btn-service"])116    analyze_btn.click(fn=analyze_conversation, inputs=chat_input, outputs=analysis_output)117 118demo.launch()119