Spaces:
Running
Running
Fix HuggingChat provider - handle welcome modal and improve input detection
Browse files- Click 'Start chatting' button to dismiss welcome modal
- Try multiple input selectors for better reliability
- Better logging of what's happening
- debug_hc_screenshots.py +130 -0
- debug_huggingchat_visible.py +155 -0
- providers/huggingchat_provider.py +39 -9
debug_hc_screenshots.py
ADDED
|
@@ -0,0 +1,130 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
Debug HuggingChat with screenshots
|
| 3 |
+
"""
|
| 4 |
+
|
| 5 |
+
import asyncio
|
| 6 |
+
import os
|
| 7 |
+
from playwright.async_api import async_playwright
|
| 8 |
+
|
| 9 |
+
HF_USERNAME = "one@bo5.store"
|
| 10 |
+
HF_PASSWORD = "Zzzzz1$."
|
| 11 |
+
|
| 12 |
+
|
| 13 |
+
async def debug_with_screenshots():
|
| 14 |
+
"""Debug HuggingChat and save screenshots at each step."""
|
| 15 |
+
print("🔍 Debugging HuggingChat with screenshots...\n")
|
| 16 |
+
|
| 17 |
+
os.makedirs("debug_screenshots", exist_ok=True)
|
| 18 |
+
|
| 19 |
+
async with async_playwright() as p:
|
| 20 |
+
browser = await p.chromium.launch(
|
| 21 |
+
headless=True,
|
| 22 |
+
args=["--disable-blink-features=AutomationControlled"],
|
| 23 |
+
)
|
| 24 |
+
|
| 25 |
+
context = await browser.new_context(
|
| 26 |
+
viewport={"width": 1920, "height": 1080},
|
| 27 |
+
user_agent="Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36",
|
| 28 |
+
)
|
| 29 |
+
|
| 30 |
+
page = await context.new_page()
|
| 31 |
+
|
| 32 |
+
# Step 1: Login page
|
| 33 |
+
print("1. Loading login page...")
|
| 34 |
+
await page.goto("https://huggingface.co/login", timeout=60000)
|
| 35 |
+
await page.screenshot(path="debug_screenshots/hf_login_page.png")
|
| 36 |
+
print(" ✓ Screenshot: hf_login_page.png")
|
| 37 |
+
|
| 38 |
+
# Step 2: Fill credentials
|
| 39 |
+
print("2. Filling credentials...")
|
| 40 |
+
await page.fill('input[name="username"]', HF_USERNAME)
|
| 41 |
+
await page.fill('input[name="password"]', HF_PASSWORD)
|
| 42 |
+
await page.screenshot(path="debug_screenshots/hf_login_filled.png")
|
| 43 |
+
print(" ✓ Screenshot: hf_login_filled.png")
|
| 44 |
+
|
| 45 |
+
# Step 3: Submit login
|
| 46 |
+
print("3. Submitting login...")
|
| 47 |
+
await page.click('button[type="submit"]')
|
| 48 |
+
await asyncio.sleep(3)
|
| 49 |
+
await page.screenshot(path="debug_screenshots/hf_after_login.png")
|
| 50 |
+
print(" ✓ Screenshot: hf_after_login.png")
|
| 51 |
+
print(f" Current URL: {page.url}")
|
| 52 |
+
|
| 53 |
+
# Step 4: Navigate to HuggingChat
|
| 54 |
+
print("4. Navigating to HuggingChat...")
|
| 55 |
+
await page.goto("https://huggingface.co/chat", timeout=60000)
|
| 56 |
+
await asyncio.sleep(3)
|
| 57 |
+
await page.screenshot(path="debug_screenshots/hc_loaded.png")
|
| 58 |
+
print(" ✓ Screenshot: hc_loaded.png")
|
| 59 |
+
print(f" Current URL: {page.url}")
|
| 60 |
+
|
| 61 |
+
# Step 5: Check for any modals/popups
|
| 62 |
+
print("5. Checking for modals or welcome screens...")
|
| 63 |
+
html = await page.content()
|
| 64 |
+
with open("debug_screenshots/hc_page.html", "w") as f:
|
| 65 |
+
f.write(html)
|
| 66 |
+
print(" ✓ Saved page HTML to hc_page.html")
|
| 67 |
+
|
| 68 |
+
# Step 6: Look for the chat interface
|
| 69 |
+
print("6. Looking for chat interface...")
|
| 70 |
+
|
| 71 |
+
# Find all buttons
|
| 72 |
+
buttons = await page.query_selector_all('button')
|
| 73 |
+
print(f" Found {len(buttons)} buttons")
|
| 74 |
+
|
| 75 |
+
# Find textareas
|
| 76 |
+
textareas = await page.query_selector_all('textarea')
|
| 77 |
+
print(f" Found {len(textareas)} textareas")
|
| 78 |
+
|
| 79 |
+
# Try to find the message input
|
| 80 |
+
input_found = False
|
| 81 |
+
for selector in ['textarea', '[contenteditable="true"]', 'input[type="text"]']:
|
| 82 |
+
try:
|
| 83 |
+
el = await page.wait_for_selector(selector, timeout=2000)
|
| 84 |
+
if el:
|
| 85 |
+
print(f" ✓ Found input: {selector}")
|
| 86 |
+
input_found = True
|
| 87 |
+
|
| 88 |
+
# Try to type
|
| 89 |
+
print("7. Attempting to type message...")
|
| 90 |
+
await page.fill(selector, "Test message from debug")
|
| 91 |
+
await asyncio.sleep(1)
|
| 92 |
+
await page.screenshot(path="debug_screenshots/hc_typed.png")
|
| 93 |
+
print(" ✓ Screenshot: hc_typed.png")
|
| 94 |
+
|
| 95 |
+
# Try to send
|
| 96 |
+
print("8. Sending message...")
|
| 97 |
+
await page.keyboard.press("Enter")
|
| 98 |
+
await asyncio.sleep(5)
|
| 99 |
+
await page.screenshot(path="debug_screenshots/hc_after_send.png")
|
| 100 |
+
print(" ✓ Screenshot: hc_after_send.png")
|
| 101 |
+
|
| 102 |
+
# Wait a bit more
|
| 103 |
+
await asyncio.sleep(5)
|
| 104 |
+
await page.screenshot(path="debug_screenshots/hc_response.png")
|
| 105 |
+
print(" ✓ Screenshot: hc_response.png")
|
| 106 |
+
break
|
| 107 |
+
except Exception as e:
|
| 108 |
+
print(f" ✗ {selector}: {e}")
|
| 109 |
+
|
| 110 |
+
if not input_found:
|
| 111 |
+
print(" ❌ Could not find any input field!")
|
| 112 |
+
|
| 113 |
+
# Check if we need to click "New chat" first
|
| 114 |
+
try:
|
| 115 |
+
new_chat = await page.query_selector('button:has-text("New chat")')
|
| 116 |
+
if new_chat:
|
| 117 |
+
print(" Found 'New chat' button, clicking...")
|
| 118 |
+
await new_chat.click()
|
| 119 |
+
await asyncio.sleep(2)
|
| 120 |
+
await page.screenshot(path="debug_screenshots/hc_after_newchat.png")
|
| 121 |
+
print(" ✓ Screenshot: hc_after_newchat.png")
|
| 122 |
+
except Exception as e:
|
| 123 |
+
print(f" No 'New chat' button: {e}")
|
| 124 |
+
|
| 125 |
+
await browser.close()
|
| 126 |
+
print("\n✅ Debug complete! Check debug_screenshots/ folder.")
|
| 127 |
+
|
| 128 |
+
|
| 129 |
+
if __name__ == "__main__":
|
| 130 |
+
asyncio.run(debug_with_screenshots())
|
debug_huggingchat_visible.py
ADDED
|
@@ -0,0 +1,155 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
Debug script for HuggingChat - Visible browser to inspect page
|
| 3 |
+
"""
|
| 4 |
+
|
| 5 |
+
import asyncio
|
| 6 |
+
import os
|
| 7 |
+
from playwright.async_api import async_playwright
|
| 8 |
+
|
| 9 |
+
# Credentials
|
| 10 |
+
HF_USERNAME = "one@bo5.store"
|
| 11 |
+
HF_PASSWORD = "Zzzzz1$."
|
| 12 |
+
|
| 13 |
+
|
| 14 |
+
async def debug_huggingchat():
|
| 15 |
+
"""Launch visible browser to debug HuggingChat."""
|
| 16 |
+
print("🔍 Launching visible browser to debug HuggingChat...")
|
| 17 |
+
print("You can watch what's happening and interact if needed.")
|
| 18 |
+
print("Press Ctrl+C to exit when done.\n")
|
| 19 |
+
|
| 20 |
+
async with async_playwright() as p:
|
| 21 |
+
browser = await p.chromium.launch(
|
| 22 |
+
headless=False, # VISIBLE browser
|
| 23 |
+
args=[
|
| 24 |
+
"--disable-blink-features=AutomationControlled",
|
| 25 |
+
"--window-size=1920,1080",
|
| 26 |
+
],
|
| 27 |
+
)
|
| 28 |
+
|
| 29 |
+
context = await browser.new_context(
|
| 30 |
+
viewport={"width": 1920, "height": 1080},
|
| 31 |
+
user_agent="Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36",
|
| 32 |
+
)
|
| 33 |
+
|
| 34 |
+
page = await context.new_page()
|
| 35 |
+
|
| 36 |
+
# Step 1: Login
|
| 37 |
+
print("Step 1: Logging in...")
|
| 38 |
+
await page.goto("https://huggingface.co/login", timeout=60000)
|
| 39 |
+
|
| 40 |
+
await page.fill('input[name="username"]', HF_USERNAME)
|
| 41 |
+
await page.fill('input[name="password"]', HF_PASSWORD)
|
| 42 |
+
await page.click('button[type="submit"]')
|
| 43 |
+
|
| 44 |
+
# Wait for login to complete
|
| 45 |
+
await page.wait_for_url(lambda url: "login" not in url, timeout=15000)
|
| 46 |
+
print("✅ Logged in!")
|
| 47 |
+
|
| 48 |
+
# Step 2: Navigate to HuggingChat
|
| 49 |
+
print("\nStep 2: Navigating to HuggingChat...")
|
| 50 |
+
await page.goto("https://huggingface.co/chat", timeout=60000)
|
| 51 |
+
await asyncio.sleep(3)
|
| 52 |
+
|
| 53 |
+
# Step 3: Inspect the page
|
| 54 |
+
print("\nStep 3: Inspecting page structure...")
|
| 55 |
+
|
| 56 |
+
# Find all buttons and their text
|
| 57 |
+
buttons = await page.query_selector_all('button')
|
| 58 |
+
print(f"Found {len(buttons)} buttons:")
|
| 59 |
+
for i, btn in enumerate(buttons[:10]): # First 10
|
| 60 |
+
text = await btn.text_content()
|
| 61 |
+
if text and text.strip():
|
| 62 |
+
print(f" {i}: {text.strip()[:50]}")
|
| 63 |
+
|
| 64 |
+
# Find all textareas
|
| 65 |
+
textareas = await page.query_selector_all('textarea')
|
| 66 |
+
print(f"\nFound {len(textareas)} textareas")
|
| 67 |
+
for i, ta in enumerate(textareas):
|
| 68 |
+
placeholder = await ta.get_attribute('placeholder')
|
| 69 |
+
print(f" {i}: placeholder='{placeholder}'")
|
| 70 |
+
|
| 71 |
+
# Find all inputs
|
| 72 |
+
inputs = await page.query_selector_all('input')
|
| 73 |
+
print(f"\nFound {len(inputs)} inputs")
|
| 74 |
+
|
| 75 |
+
# Step 4: Try to find and click "New Chat" or similar
|
| 76 |
+
print("\nStep 4: Looking for 'New chat' button...")
|
| 77 |
+
try:
|
| 78 |
+
new_chat = await page.wait_for_selector('button:has-text("New chat")', timeout=5000)
|
| 79 |
+
if new_chat:
|
| 80 |
+
print("Found 'New chat' button, clicking...")
|
| 81 |
+
await new_chat.click()
|
| 82 |
+
await asyncio.sleep(2)
|
| 83 |
+
except:
|
| 84 |
+
print("No 'New chat' button found (might already be in chat)")
|
| 85 |
+
|
| 86 |
+
# Step 5: Find the message input
|
| 87 |
+
print("\nStep 5: Finding message input...")
|
| 88 |
+
|
| 89 |
+
# Try multiple selectors
|
| 90 |
+
input_selectors = [
|
| 91 |
+
'textarea[placeholder*="Ask"]',
|
| 92 |
+
'textarea[placeholder*="Message"]',
|
| 93 |
+
'textarea',
|
| 94 |
+
'[contenteditable="true"]',
|
| 95 |
+
'input[type="text"]',
|
| 96 |
+
]
|
| 97 |
+
|
| 98 |
+
found_input = None
|
| 99 |
+
for sel in input_selectors:
|
| 100 |
+
try:
|
| 101 |
+
el = await page.wait_for_selector(sel, timeout=3000)
|
| 102 |
+
if el:
|
| 103 |
+
print(f"✅ Found input: {sel}")
|
| 104 |
+
found_input = sel
|
| 105 |
+
break
|
| 106 |
+
except:
|
| 107 |
+
print(f"❌ Not found: {sel}")
|
| 108 |
+
|
| 109 |
+
if found_input:
|
| 110 |
+
# Step 6: Type a message
|
| 111 |
+
print("\nStep 6: Typing test message...")
|
| 112 |
+
await page.fill(found_input, "Say 'Test successful from debug script'")
|
| 113 |
+
await asyncio.sleep(1)
|
| 114 |
+
|
| 115 |
+
# Step 7: Send message
|
| 116 |
+
print("Step 7: Sending message...")
|
| 117 |
+
await page.keyboard.press("Enter")
|
| 118 |
+
|
| 119 |
+
# Step 8: Wait and watch for response
|
| 120 |
+
print("\nStep 8: Waiting for response (30 seconds)...")
|
| 121 |
+
print("Watch the browser window to see what happens!\n")
|
| 122 |
+
|
| 123 |
+
for i in range(30):
|
| 124 |
+
await asyncio.sleep(1)
|
| 125 |
+
if i % 5 == 0:
|
| 126 |
+
# Try to extract any response text
|
| 127 |
+
try:
|
| 128 |
+
messages = await page.evaluate("""
|
| 129 |
+
() => {
|
| 130 |
+
const msgs = document.querySelectorAll('[data-message-author-role="assistant"], .assistant-message, [class*="assistant"], article');
|
| 131 |
+
return Array.from(msgs).map(m => m.innerText || m.textContent).slice(-1);
|
| 132 |
+
}
|
| 133 |
+
""")
|
| 134 |
+
if messages and messages[0]:
|
| 135 |
+
print(f"Second {i}: Response preview: {messages[0][:100]}...")
|
| 136 |
+
except:
|
| 137 |
+
pass
|
| 138 |
+
else:
|
| 139 |
+
print("❌ Could not find any input field!")
|
| 140 |
+
|
| 141 |
+
print("\n⏳ Keeping browser open for 60 seconds...")
|
| 142 |
+
print("You can manually inspect the page now.")
|
| 143 |
+
print("Press Ctrl+C to close.\n")
|
| 144 |
+
|
| 145 |
+
try:
|
| 146 |
+
await asyncio.sleep(60)
|
| 147 |
+
except KeyboardInterrupt:
|
| 148 |
+
pass
|
| 149 |
+
|
| 150 |
+
await browser.close()
|
| 151 |
+
print("✅ Debug session complete.")
|
| 152 |
+
|
| 153 |
+
|
| 154 |
+
if __name__ == "__main__":
|
| 155 |
+
asyncio.run(debug_huggingchat())
|
providers/huggingchat_provider.py
CHANGED
|
@@ -164,7 +164,24 @@ class HuggingChatProvider(BaseProvider):
|
|
| 164 |
# Navigate to HuggingChat
|
| 165 |
await page.goto("https://huggingface.co/chat", timeout=60000)
|
| 166 |
|
| 167 |
-
# Wait for
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 168 |
await asyncio.sleep(2)
|
| 169 |
|
| 170 |
# If specific model requested (not omni), try to select it
|
|
@@ -175,15 +192,28 @@ class HuggingChatProvider(BaseProvider):
|
|
| 175 |
|
| 176 |
await asyncio.sleep(self.HYDRATION_DELAY)
|
| 177 |
|
| 178 |
-
# Find and use the chat input
|
| 179 |
-
input_selector =
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 180 |
|
| 181 |
-
|
| 182 |
-
|
| 183 |
-
|
| 184 |
-
|
| 185 |
-
|
| 186 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 187 |
|
| 188 |
# Type the message
|
| 189 |
full_prompt = prompt
|
|
|
|
| 164 |
# Navigate to HuggingChat
|
| 165 |
await page.goto("https://huggingface.co/chat", timeout=60000)
|
| 166 |
|
| 167 |
+
# Wait for page to load
|
| 168 |
+
await asyncio.sleep(3)
|
| 169 |
+
|
| 170 |
+
# Handle welcome modal if present
|
| 171 |
+
try:
|
| 172 |
+
start_btn = await page.wait_for_selector(
|
| 173 |
+
'button:has-text("Start chatting")',
|
| 174 |
+
timeout=5000
|
| 175 |
+
)
|
| 176 |
+
if start_btn:
|
| 177 |
+
logger.info("HuggingChat: Dismissing welcome modal...")
|
| 178 |
+
await start_btn.click()
|
| 179 |
+
await asyncio.sleep(2)
|
| 180 |
+
logger.info("HuggingChat: Welcome modal dismissed")
|
| 181 |
+
except:
|
| 182 |
+
logger.info("HuggingChat: No welcome modal found")
|
| 183 |
+
|
| 184 |
+
# Wait for chat interface to fully load
|
| 185 |
await asyncio.sleep(2)
|
| 186 |
|
| 187 |
# If specific model requested (not omni), try to select it
|
|
|
|
| 192 |
|
| 193 |
await asyncio.sleep(self.HYDRATION_DELAY)
|
| 194 |
|
| 195 |
+
# Find and use the chat input - try multiple strategies
|
| 196 |
+
input_selector = None
|
| 197 |
+
input_selectors = [
|
| 198 |
+
'textarea[placeholder*="Ask"]',
|
| 199 |
+
'textarea[placeholder*="Message"]',
|
| 200 |
+
'textarea',
|
| 201 |
+
'[contenteditable="true"]',
|
| 202 |
+
'input[type="text"]',
|
| 203 |
+
]
|
| 204 |
|
| 205 |
+
for sel in input_selectors:
|
| 206 |
+
try:
|
| 207 |
+
el = await page.wait_for_selector(sel, timeout=3000)
|
| 208 |
+
if el:
|
| 209 |
+
input_selector = sel
|
| 210 |
+
logger.info(f"HuggingChat: Found input using {sel}")
|
| 211 |
+
break
|
| 212 |
+
except:
|
| 213 |
+
continue
|
| 214 |
+
|
| 215 |
+
if not input_selector:
|
| 216 |
+
raise RuntimeError("Could not find chat input field")
|
| 217 |
|
| 218 |
# Type the message
|
| 219 |
full_prompt = prompt
|