dindizz commited on
Commit
2731e27
·
verified ·
1 Parent(s): 8ffb139

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +32 -34
app.py CHANGED
@@ -1,54 +1,52 @@
1
- import requests
2
- from bs4 import BeautifulSoup
3
  from transformers import pipeline, AutoTokenizer, AutoModelForCausalLM
4
  import gradio as gr
5
 
6
- # Function to scrape LinkedIn profile
7
- def scrape_linkedin_profile(url):
8
- response = requests.get(url)
9
- if response.status_code == 200:
10
- soup = BeautifulSoup(response.content, 'html.parser')
11
- profile = {}
 
12
 
13
- # Example scraping logic (adjust based on actual LinkedIn page structure)
14
- profile['name'] = soup.find('title').text.strip()
15
- profile['headline'] = soup.find('div', {'class': 'ph5'}).text.strip()
16
- profile['about'] = soup.find('section', {'id': 'about'}).text.strip() if soup.find('section', {'id': 'about'}) else "No About Section"
 
 
 
17
 
18
- return profile
19
- else:
20
- return f"Failed to fetch LinkedIn page, status code: {response.status_code}"
21
-
22
- # Function to generate roast using a Gen AI model
23
- def generate_roast(profile_data):
24
- # Initialize the Gen AI model from Hugging Face
25
  tokenizer = AutoTokenizer.from_pretrained("EleutherAI/gpt-neo-1.3B")
26
  model = AutoModelForCausalLM.from_pretrained("EleutherAI/gpt-neo-1.3B")
27
 
28
- # Format profile into a prompt
29
- prompt = f"Roast this LinkedIn profile:\nName: {profile_data['name']}\nHeadline: {profile_data['headline']}\nAbout: {profile_data['about']}\n\nRoast:"
30
 
31
  generator = pipeline('text-generation', model=model, tokenizer=tokenizer)
32
-
33
- # Generate roast
34
  roast = generator(prompt, max_length=150, num_return_sequences=1)
35
 
36
  return roast[0]['generated_text']
37
 
38
  # Gradio interface function
39
- def roast_linkedin(url):
40
- profile_data = scrape_linkedin_profile(url)
41
-
42
- if isinstance(profile_data, dict):
43
- roast = generate_roast(profile_data)
44
- return roast
45
  else:
46
- return profile_data
 
 
 
47
 
48
  # Create Gradio interface
49
- interface = gr.Interface(fn=roast_linkedin, inputs="text", outputs="text",
50
- title="LinkedIn Profile Roaster",
51
- description="Enter the LinkedIn profile URL and get a humorous roast generated by AI!")
52
 
53
- # Launch Gradio app
54
  interface.launch()
 
1
+ import fitz # PyMuPDF for PDF handling
2
+ import docx
3
  from transformers import pipeline, AutoTokenizer, AutoModelForCausalLM
4
  import gradio as gr
5
 
6
+ # Function to extract text from PDF
7
+ def extract_text_from_pdf(pdf_file):
8
+ doc = fitz.open(pdf_file)
9
+ text = ""
10
+ for page in doc:
11
+ text += page.get_text()
12
+ return text
13
 
14
+ # Function to extract text from DOCX
15
+ def extract_text_from_docx(docx_file):
16
+ doc = docx.Document(docx_file)
17
+ full_text = []
18
+ for paragraph in doc.paragraphs:
19
+ full_text.append(paragraph.text)
20
+ return '\n'.join(full_text)
21
 
22
+ # Function to generate roast based on resume text
23
+ def generate_roast(resume_text):
 
 
 
 
 
24
  tokenizer = AutoTokenizer.from_pretrained("EleutherAI/gpt-neo-1.3B")
25
  model = AutoModelForCausalLM.from_pretrained("EleutherAI/gpt-neo-1.3B")
26
 
27
+ prompt = f"Roast this resume:\n\n{resume_text}\n\nRoast:"
 
28
 
29
  generator = pipeline('text-generation', model=model, tokenizer=tokenizer)
 
 
30
  roast = generator(prompt, max_length=150, num_return_sequences=1)
31
 
32
  return roast[0]['generated_text']
33
 
34
  # Gradio interface function
35
+ def roast_resume(file):
36
+ if file.name.endswith('.pdf'):
37
+ resume_text = extract_text_from_pdf(file.name)
38
+ elif file.name.endswith('.docx'):
39
+ resume_text = extract_text_from_docx(file.name)
 
40
  else:
41
+ return "Unsupported file format. Please upload a PDF or DOCX file."
42
+
43
+ roast = generate_roast(resume_text)
44
+ return roast
45
 
46
  # Create Gradio interface
47
+ interface = gr.Interface(fn=roast_resume, inputs="file", outputs="text",
48
+ title="Resume Roaster",
49
+ description="Upload your resume in PDF or DOCX format, and let the AI roast it!")
50
 
51
+ # Launch the app
52
  interface.launch()