hamza2923 commited on
Commit
7028185
·
verified ·
1 Parent(s): c1c51a7

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +36 -13
app.py CHANGED
@@ -37,27 +37,31 @@ class TranscriptResponse(BaseModel):
37
  processing_time: float
38
 
39
  def init_driver():
 
 
 
 
40
  options = Options()
41
  options.add_argument("--headless=new")
42
  options.add_argument("--no-sandbox")
43
  options.add_argument("--disable-dev-shm-usage")
44
  options.add_argument("--disable-gpu")
45
- options.add_argument("--window-size=1280,1696")
46
-
47
- # CORRECT PATH FOR HUGGING FACE
48
- options.binary_location = "/usr/bin/google-chrome-stable" # Changed from google-chrome
49
 
50
- service = Service(
51
- executable_path="/usr/bin/chromedriver",
52
- service_args=["--verbose", "--log-path=/tmp/chromedriver.log"]
53
- )
54
 
55
  try:
 
 
56
  driver = webdriver.Chrome(service=service, options=options)
57
  return driver
58
  except Exception as e:
59
- logger.error(f"Driver initialization failed: {str(e)}")
60
- raise
 
 
 
 
61
 
62
 
63
  @app.post("/transcript", response_model=TranscriptResponse)
@@ -146,16 +150,35 @@ async def get_transcript(request: VideoRequest):
146
 
147
  @app.get("/health")
148
  async def health_check():
 
149
  paths = {
150
- "chrome": "/usr/bin/google-chrome-stable", # Consistent with binary_location
151
  "chromedriver": "/usr/bin/chromedriver"
152
  }
153
  exists = {name: os.path.exists(path) for name, path in paths.items()}
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
154
  return {
155
  "status": "OK",
156
  "paths": exists,
157
- "chrome_version": os.popen("/usr/bin/google-chrome-stable --version").read().strip() if exists["chrome"] else "Not found",
158
- "chromedriver_version": os.popen("/usr/bin/chromedriver --version").read().strip() if exists["chromedriver"] else "Not found"
 
159
  }
160
 
161
  if __name__ == "__main__":
 
37
  processing_time: float
38
 
39
  def init_driver():
40
+ from selenium import webdriver
41
+ from selenium.webdriver.chrome.service import Service
42
+ from selenium.webdriver.chrome.options import Options
43
+
44
  options = Options()
45
  options.add_argument("--headless=new")
46
  options.add_argument("--no-sandbox")
47
  options.add_argument("--disable-dev-shm-usage")
48
  options.add_argument("--disable-gpu")
 
 
 
 
49
 
50
+ # For Hugging Face Spaces
51
+ options.binary_location = "/usr/bin/google-chrome"
 
 
52
 
53
  try:
54
+ # Try with service first
55
+ service = Service(executable_path="/usr/bin/chromedriver")
56
  driver = webdriver.Chrome(service=service, options=options)
57
  return driver
58
  except Exception as e:
59
+ try:
60
+ # Fallback without service
61
+ driver = webdriver.Chrome(options=options)
62
+ return driver
63
+ except Exception as e:
64
+ raise Exception(f"Both driver initialization methods failed: {str(e)}")
65
 
66
 
67
  @app.post("/transcript", response_model=TranscriptResponse)
 
150
 
151
  @app.get("/health")
152
  async def health_check():
153
+ import os
154
  paths = {
155
+ "chrome": "/usr/bin/google-chrome",
156
  "chromedriver": "/usr/bin/chromedriver"
157
  }
158
  exists = {name: os.path.exists(path) for name, path in paths.items()}
159
+
160
+ # Try to get versions
161
+ chrome_version = "Not found"
162
+ chromedriver_version = "Not found"
163
+
164
+ if exists["chrome"]:
165
+ try:
166
+ chrome_version = os.popen("/usr/bin/google-chrome --version").read().strip()
167
+ except:
168
+ pass
169
+
170
+ if exists["chromedriver"]:
171
+ try:
172
+ chromedriver_version = os.popen("/usr/bin/chromedriver --version").read().strip()
173
+ except:
174
+ pass
175
+
176
  return {
177
  "status": "OK",
178
  "paths": exists,
179
+ "chrome_version": chrome_version,
180
+ "chromedriver_version": chromedriver_version,
181
+ "working": all(exists.values())
182
  }
183
 
184
  if __name__ == "__main__":