Spaces:
Paused
Paused
Update app.py
Browse files
app.py
CHANGED
|
@@ -9,14 +9,19 @@ import time
|
|
| 9 |
|
| 10 |
# Function to generate image URL
|
| 11 |
def generate_image(prompt):
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
|
|
|
| 17 |
|
| 18 |
# Initialize the WebDriver
|
| 19 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 20 |
|
| 21 |
try:
|
| 22 |
# Open the website
|
|
@@ -49,7 +54,9 @@ def generate_image(prompt):
|
|
| 49 |
# Extract the image URL
|
| 50 |
image_url = generated_image.get_attribute("src")
|
| 51 |
return image_url
|
| 52 |
-
|
|
|
|
|
|
|
| 53 |
finally:
|
| 54 |
# Close the browser
|
| 55 |
driver.quit()
|
|
|
|
| 9 |
|
| 10 |
# Function to generate image URL
|
| 11 |
def generate_image(prompt):
|
| 12 |
+
chrome_options = Options()
|
| 13 |
+
chrome_options.add_argument("--headless")
|
| 14 |
+
chrome_options.add_argument("--no-sandbox")
|
| 15 |
+
chrome_options.add_argument("--disable-dev-shm-usage")
|
| 16 |
+
chrome_options.add_argument("--disable-gpu")
|
| 17 |
+
chrome_options.add_argument("window-size=1920x1080")
|
| 18 |
|
| 19 |
# Initialize the WebDriver
|
| 20 |
+
try:
|
| 21 |
+
driver = webdriver.Chrome(options=chrome_options)
|
| 22 |
+
except Exception as e:
|
| 23 |
+
print(f"Failed to initialize ChromeDriver: {e}. Falling back to webdriver-manager.")
|
| 24 |
+
driver = webdriver.Chrome(service=Service(ChromeDriverManager().install()), options=chrome_options)
|
| 25 |
|
| 26 |
try:
|
| 27 |
# Open the website
|
|
|
|
| 54 |
# Extract the image URL
|
| 55 |
image_url = generated_image.get_attribute("src")
|
| 56 |
return image_url
|
| 57 |
+
|
| 58 |
+
except Exception as e:
|
| 59 |
+
return f"Error: {str(e)}"
|
| 60 |
finally:
|
| 61 |
# Close the browser
|
| 62 |
driver.quit()
|