nmurugesh commited on
Commit
4b863d4
·
verified ·
1 Parent(s): ff844c6

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +21 -23
app.py CHANGED
@@ -3,40 +3,38 @@ import gradio as gr
3
  from playwright.sync_api import sync_playwright
4
  from bs4 import BeautifulSoup
5
 
6
- import os
7
- from playwright.sync_api import sync_playwright
8
-
9
- # Ensure Playwright browsers are installed before using them
10
- os.system("playwright install --with-deps")
11
 
12
  def scrape_profile(url):
13
- with sync_playwright() as p:
14
- browser = p.chromium.launch(headless=True)
15
- page = browser.new_page()
16
- page.goto(url)
17
-
18
- # Extract basic profile info (Modify as needed)
19
- name = page.locator("h1").inner_text() if page.locator("h1").count() > 0 else "Name not found"
20
- profile_summary = page.locator(".summary-class").inner_text() if page.locator(".summary-class").count() > 0 else "Summary not found"
21
-
22
- browser.close()
23
- return {"Name": name, "Summary": profile_summary}
 
 
 
 
 
24
 
25
  # Gradio UI
26
- import gradio as gr
27
-
28
- def fetch_profile(url):
29
- data = scrape_profile(url)
30
- return f"Name: {data['Name']}\nSummary: {data['Summary']}"
31
-
32
  iface = gr.Interface(
33
- fn=fetch_profile,
34
  inputs=gr.Textbox(label="Enter LinkedIn Profile URL"),
35
  outputs=gr.Textbox(label="Profile Data"),
36
  live=True
37
  )
38
 
39
  iface.launch()
 
40
 
41
 
42
 
 
3
  from playwright.sync_api import sync_playwright
4
  from bs4 import BeautifulSoup
5
 
6
+ import requests
7
+ from bs4 import BeautifulSoup
8
+ import gradio as gr
 
 
9
 
10
  def scrape_profile(url):
11
+ headers = {
12
+ "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36"
13
+ }
14
+
15
+ response = requests.get(url, headers=headers)
16
+
17
+ if response.status_code != 200:
18
+ return "Failed to retrieve profile. Ensure the URL is correct and accessible."
19
+
20
+ soup = BeautifulSoup(response.text, "html.parser")
21
+
22
+ # Extract profile details (Modify selectors as needed)
23
+ name = soup.find("h1").text.strip() if soup.find("h1") else "Name not found"
24
+ summary = soup.find("p").text.strip() if soup.find("p") else "Summary not found"
25
+
26
+ return f"Name: {name}\nSummary: {summary}"
27
 
28
  # Gradio UI
 
 
 
 
 
 
29
  iface = gr.Interface(
30
+ fn=scrape_profile,
31
  inputs=gr.Textbox(label="Enter LinkedIn Profile URL"),
32
  outputs=gr.Textbox(label="Profile Data"),
33
  live=True
34
  )
35
 
36
  iface.launch()
37
+
38
 
39
 
40