Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,29 +1,8 @@
|
|
|
|
|
| 1 |
import subprocess
|
| 2 |
from playwright.async_api import async_playwright
|
| 3 |
-
|
| 4 |
-
async def main():
|
| 5 |
-
# Check if the browser binaries exist, if not, download them
|
| 6 |
-
try:
|
| 7 |
-
subprocess.check_output(["which", "chromium"])
|
| 8 |
-
except FileNotFoundError:
|
| 9 |
-
print("Browser binaries not found. Downloading...")
|
| 10 |
-
subprocess.run(["playwright", "install"])
|
| 11 |
-
|
| 12 |
-
# Your existing initialization code follows
|
| 13 |
-
async with async_playwright() as p:
|
| 14 |
-
browser = await p.chromium.launch()
|
| 15 |
-
# Continue with your application logic...
|
| 16 |
-
|
| 17 |
-
# Run the main function
|
| 18 |
-
if __name__ == "__main__":
|
| 19 |
-
import asyncio
|
| 20 |
-
asyncio.run(main())
|
| 21 |
-
|
| 22 |
-
|
| 23 |
import gradio as gr
|
| 24 |
from transformers import AutoTokenizer, AutoModelForCausalLM, pipeline
|
| 25 |
-
from playwright.async_api import async_playwright
|
| 26 |
-
import json
|
| 27 |
|
| 28 |
# Define model and inference parameters
|
| 29 |
MODEL_NAME = "HuggingFaceH4/zephyr-7b-beta"
|
|
@@ -46,6 +25,14 @@ def generate_actions(input_text):
|
|
| 46 |
|
| 47 |
# Function to initialize browser and page (now asynchronous)
|
| 48 |
async def initialize_browser():
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 49 |
async with async_playwright() as p:
|
| 50 |
browser = await p.chromium.launch()
|
| 51 |
page = await browser.new_page()
|
|
|
|
| 1 |
+
import os
|
| 2 |
import subprocess
|
| 3 |
from playwright.async_api import async_playwright
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 4 |
import gradio as gr
|
| 5 |
from transformers import AutoTokenizer, AutoModelForCausalLM, pipeline
|
|
|
|
|
|
|
| 6 |
|
| 7 |
# Define model and inference parameters
|
| 8 |
MODEL_NAME = "HuggingFaceH4/zephyr-7b-beta"
|
|
|
|
| 25 |
|
| 26 |
# Function to initialize browser and page (now asynchronous)
|
| 27 |
async def initialize_browser():
|
| 28 |
+
# Attempt to download browser binaries if not already present
|
| 29 |
+
try:
|
| 30 |
+
subprocess.check_output(["which", "chromium"], stderr=subprocess.STDOUT)
|
| 31 |
+
except subprocess.CalledProcessError:
|
| 32 |
+
print("Chromium not found. Attempting to download...")
|
| 33 |
+
# Note: Directly executing 'playwright install' in Python is not supported.
|
| 34 |
+
# You would need to ensure the environment is pre-configured or use a different method to install the browser.
|
| 35 |
+
|
| 36 |
async with async_playwright() as p:
|
| 37 |
browser = await p.chromium.launch()
|
| 38 |
page = await browser.new_page()
|