Spaces:
Sleeping
Sleeping
Update src/streamlit_app.py
Browse files5 unmodified lines678910111256 unmodified lines69707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173164 unmodified lines3383393402413415 unmodified linesimport timeimport openpyxlfrom openpyxl import Workbookimport streamlit.components.v1 as components
# page configst.set_page_config(page_title="Book Scraper", layout="wide")56 unmodified lines</style>""", unsafe_allow_html=True)
# ============== الشخصية المساعدة المتحركة (تختار المستخدم شخصيته، تتحرك وتتفاعل مع كل زر) ==============components.html("""<div id="characterPicker" style="position:fixed; top:10px; left:10px; display:flex; flex-wrap:wrap; gap:8px; pointer-events:auto;"></div>
<script type="module"> import { initAgent } from 'https://cdn.jsdelivr.net/npm/clippyjs/dist/index.mjs'; import * as clippyAgents from 'https://cdn.jsdelivr.net/npm/clippyjs/dist/agents/index.mjs';
// نخلي الـ iframe يغطي كامل الصفحة بدون ما يحجب أزرار Streamlit const frame = window.frameElement; if(frame){ frame.style.position = 'fixed'; frame.style.top = '0'; frame.style.left = '0'; frame.style.width = '100vw'; frame.style.height = '100vh'; frame.style.zIndex = '999999'; frame.style.border = 'none'; frame.style.pointerEvents = 'none'; } document.body.style.pointerEvents = 'none'; document.getElementById('characterPicker').style.pointerEvents = 'auto';
const CHARACTERS = [ { key: 'Clippy', label: 'كليبي 📎' }, { key: 'Merlin', label: 'مارلن 🧙' }, { key: 'Rover', label: 'روفر 🐶' }, { key: 'Links', label: 'لينكس 🐱' }, { key: 'Genius', label: 'الفيلسوف 🧑🔬' }, { key: 'Peedy', label: 'بيدي 🦜' }, { key: 'Bonzi', label: 'بونزي 🐵' }, { key: 'Rocky', label: 'روكي 🐧' }, { key: 'F1', label: 'روبوت 🤖' }, ];
let currentAgent = null; let roamTimer = null; let lastReactionTime = 0;
const IDLE_TIPS = ['أحتاج مساعدة؟ 😊', 'جرب تحمل الملف Excel أو CSV!', 'دور عن كتاب جديد!']; const CLICK_REACTIONS = ['أوه، شنو راح تسوي هسة؟', 'خيار زين! 👍', 'تمام، شغال؟'];
function randomPoint(){ return { x: 40 + Math.random() * (window.innerWidth - 150), y: 80 + Math.random() * (window.innerHeight - 200) }; }
function startRoaming(agent){ clearInterval(roamTimer); roamTimer = setInterval(() => { if(!agent) return; const p = randomPoint(); agent.moveTo(p.x, p.y); if(Math.random() < 0.35){ agent.speak(IDLE_TIPS[Math.floor(Math.random()*IDLE_TIPS.length)]); } else { agent.animate(); } }, 10000); }
function reactToClick(e){ if(!currentAgent) return; const now = Date.now(); if(now - lastReactionTime < 1500) return; lastReactionTime = now; currentAgent.stopCurrent(); currentAgent.gestureAt(e.clientX, e.clientY); currentAgent.animate(); if(Math.random() < 0.5){ currentAgent.speak(CLICK_REACTIONS[Math.floor(Math.random()*CLICK_REACTIONS.length)]); } }
// نستمع للضغطات على صفحة Streamlit الحقيقية (خارج الـ iframe) try{ window.parent.document.addEventListener('click', (e) => { if(e.target.closest('button, a, [role="button"]')){ reactToClick(e); } }); }catch(err){ console.warn('تعذر الوصول لصفحة Streamlit الأساسية', err); }
async function switchTo(name){ if(!clippyAgents[name]) return; clearInterval(roamTimer); if(currentAgent){ try{ currentAgent.hide(); currentAgent.dispose(); }catch(e){} currentAgent = null; } const agent = await initAgent(clippyAgents[name]); currentAgent = agent; agent.show(); agent.speak('مرحباً! اخترتني، هلا 👋'); startRoaming(agent); localStorage.setItem('chosenCharacter', name); }
function renderPicker(){ const el = document.getElementById('characterPicker'); el.innerHTML = CHARACTERS.map(c => `<button data-key="${c.key}" style="padding:8px 14px; border-radius:20px; border:1px solid #ccc; background:#fff; cursor:pointer;">${c.label}</button>`).join(''); el.querySelectorAll('button').forEach(btn => btn.addEventListener('click', () => switchTo(btn.dataset.key))); }
renderPicker(); const saved = localStorage.getItem('chosenCharacter') || 'Clippy'; switchTo(saved);</script>""", height=0)
# titletitle_text = "أداة استخراج بيانات الكتب" if AR else "Book Data Scraper"st.markdown(f'<div class="title-bar">{title_text}</div>', unsafe_allow_html=True)164 unmodified lines if auto_refresh == 0: break time.sleep(auto_refresh) st.rerun() st.rerun()src/streamlit_app.py+101-1