Spaces:
Sleeping
Sleeping
File size: 5,674 Bytes
36900ae | 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 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 | """
Debug script for HuggingChat - Visible browser to inspect page
"""
import asyncio
import os
from playwright.async_api import async_playwright
# Credentials
HF_USERNAME = "one@bo5.store"
HF_PASSWORD = "Zzzzz1$."
async def debug_huggingchat():
"""Launch visible browser to debug HuggingChat."""
print("🔍 Launching visible browser to debug HuggingChat...")
print("You can watch what's happening and interact if needed.")
print("Press Ctrl+C to exit when done.\n")
async with async_playwright() as p:
browser = await p.chromium.launch(
headless=False, # VISIBLE browser
args=[
"--disable-blink-features=AutomationControlled",
"--window-size=1920,1080",
],
)
context = await browser.new_context(
viewport={"width": 1920, "height": 1080},
user_agent="Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36",
)
page = await context.new_page()
# Step 1: Login
print("Step 1: Logging in...")
await page.goto("https://huggingface.co/login", timeout=60000)
await page.fill('input[name="username"]', HF_USERNAME)
await page.fill('input[name="password"]', HF_PASSWORD)
await page.click('button[type="submit"]')
# Wait for login to complete
await page.wait_for_url(lambda url: "login" not in url, timeout=15000)
print("✅ Logged in!")
# Step 2: Navigate to HuggingChat
print("\nStep 2: Navigating to HuggingChat...")
await page.goto("https://huggingface.co/chat", timeout=60000)
await asyncio.sleep(3)
# Step 3: Inspect the page
print("\nStep 3: Inspecting page structure...")
# Find all buttons and their text
buttons = await page.query_selector_all('button')
print(f"Found {len(buttons)} buttons:")
for i, btn in enumerate(buttons[:10]): # First 10
text = await btn.text_content()
if text and text.strip():
print(f" {i}: {text.strip()[:50]}")
# Find all textareas
textareas = await page.query_selector_all('textarea')
print(f"\nFound {len(textareas)} textareas")
for i, ta in enumerate(textareas):
placeholder = await ta.get_attribute('placeholder')
print(f" {i}: placeholder='{placeholder}'")
# Find all inputs
inputs = await page.query_selector_all('input')
print(f"\nFound {len(inputs)} inputs")
# Step 4: Try to find and click "New Chat" or similar
print("\nStep 4: Looking for 'New chat' button...")
try:
new_chat = await page.wait_for_selector('button:has-text("New chat")', timeout=5000)
if new_chat:
print("Found 'New chat' button, clicking...")
await new_chat.click()
await asyncio.sleep(2)
except:
print("No 'New chat' button found (might already be in chat)")
# Step 5: Find the message input
print("\nStep 5: Finding message input...")
# Try multiple selectors
input_selectors = [
'textarea[placeholder*="Ask"]',
'textarea[placeholder*="Message"]',
'textarea',
'[contenteditable="true"]',
'input[type="text"]',
]
found_input = None
for sel in input_selectors:
try:
el = await page.wait_for_selector(sel, timeout=3000)
if el:
print(f"✅ Found input: {sel}")
found_input = sel
break
except:
print(f"❌ Not found: {sel}")
if found_input:
# Step 6: Type a message
print("\nStep 6: Typing test message...")
await page.fill(found_input, "Say 'Test successful from debug script'")
await asyncio.sleep(1)
# Step 7: Send message
print("Step 7: Sending message...")
await page.keyboard.press("Enter")
# Step 8: Wait and watch for response
print("\nStep 8: Waiting for response (30 seconds)...")
print("Watch the browser window to see what happens!\n")
for i in range(30):
await asyncio.sleep(1)
if i % 5 == 0:
# Try to extract any response text
try:
messages = await page.evaluate("""
() => {
const msgs = document.querySelectorAll('[data-message-author-role="assistant"], .assistant-message, [class*="assistant"], article');
return Array.from(msgs).map(m => m.innerText || m.textContent).slice(-1);
}
""")
if messages and messages[0]:
print(f"Second {i}: Response preview: {messages[0][:100]}...")
except:
pass
else:
print("❌ Could not find any input field!")
print("\n⏳ Keeping browser open for 60 seconds...")
print("You can manually inspect the page now.")
print("Press Ctrl+C to close.\n")
try:
await asyncio.sleep(60)
except KeyboardInterrupt:
pass
await browser.close()
print("✅ Debug session complete.")
if __name__ == "__main__":
asyncio.run(debug_huggingchat())
|