Spaces:
Build error
Build error
File size: 4,408 Bytes
46e741d |
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 |
#!/usr/bin/env python3
"""
Debug script to find correct Gradio chat message selectors.
"""
import time
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
def main():
print("π Finding Gradio 6.x chat message selectors...")
options = webdriver.ChromeOptions()
# options.add_argument('--headless')
options.add_argument('--no-sandbox')
options.add_argument('--disable-dev-shm-usage')
driver = webdriver.Chrome(options=options)
try:
driver.get("http://localhost:7860")
# Wait for Gradio to load
WebDriverWait(driver, 30).until(
EC.presence_of_element_located((By.TAG_NAME, "gradio-app"))
)
time.sleep(3)
# Load a character to initialize chat
print("\nπ Loading character to initialize chat...")
dropdowns = driver.find_elements(By.TAG_NAME, "select")
if dropdowns:
for dropdown in dropdowns:
if dropdown.is_displayed():
dropdown.click()
time.sleep(0.5)
options = dropdown.find_elements(By.TAG_NAME, "option")
if len(options) > 1:
options[1].click() # Select first non-empty option
break
time.sleep(1)
# Click Load Character button
buttons = driver.find_elements(By.TAG_NAME, "button")
for btn in buttons:
if "load character" in btn.text.lower():
print(f" Clicking: {btn.text}")
btn.click()
time.sleep(3) # Wait for character to load and welcome message
break
print("\nπ Testing various selectors for chat messages:")
selectors = [
("CLASS_NAME: message", By.CLASS_NAME, "message"),
("CLASS_NAME: message-row", By.CLASS_NAME, "message-row"),
("CLASS_NAME: bot", By.CLASS_NAME, "bot"),
("CLASS_NAME: user", By.CLASS_NAME, "user"),
("CSS: .message", By.CSS_SELECTOR, ".message"),
("CSS: .message-row", By.CSS_SELECTOR, ".message-row"),
("CSS: [data-testid='bot']", By.CSS_SELECTOR, "[data-testid='bot']"),
("CSS: [data-testid='user']", By.CSS_SELECTOR, "[data-testid='user']"),
("CSS: .chatbot .message", By.CSS_SELECTOR, ".chatbot .message"),
("CSS: div[data-testid]", By.CSS_SELECTOR, "div[data-testid]"),
("TAG: p", By.TAG_NAME, "p"),
]
for name, by, selector in selectors:
try:
elements = driver.find_elements(by, selector)
print(f"\n{name}: Found {len(elements)} elements")
if elements:
# Show first few elements' text
for i, elem in enumerate(elements[:3]):
text = elem.text.strip()
if text:
print(f" [{i}] {text[:100]}")
else:
# Try getting innerHTML if text is empty
html = elem.get_attribute('innerHTML')
if html:
print(f" [{i}] (HTML) {html[:100]}")
except Exception as e:
print(f"{name}: Error - {e}")
print("\n" + "="*80)
print("π‘ RECOMMENDATION:")
print("="*80)
# Try to find any text that looks like the welcome message
body = driver.find_element(By.TAG_NAME, "body")
body_text = body.text
if "Welcome" in body_text or "Prancing Pony" in body_text:
print("β
Welcome message IS visible in the page!")
print("The chat is working, we just need the right selector.")
else:
print("β No welcome message found - chat may not be initialized")
# Look for all p tags with substantial text
print("\nπ All <p> tags with text content:")
p_tags = driver.find_elements(By.TAG_NAME, "p")
for i, p in enumerate(p_tags[:10]):
text = p.text.strip()
if len(text) > 10:
print(f" p[{i}]: {text[:150]}")
finally:
driver.quit()
if __name__ == "__main__":
main()
|