Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,54 +1,52 @@
|
|
| 1 |
-
import
|
| 2 |
-
|
| 3 |
from transformers import pipeline, AutoTokenizer, AutoModelForCausalLM
|
| 4 |
import gradio as gr
|
| 5 |
|
| 6 |
-
# Function to
|
| 7 |
-
def
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
|
|
|
| 12 |
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
|
|
|
|
|
|
|
|
|
| 17 |
|
| 18 |
-
|
| 19 |
-
|
| 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 |
-
|
| 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
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
return roast
|
| 45 |
else:
|
| 46 |
-
return
|
|
|
|
|
|
|
|
|
|
| 47 |
|
| 48 |
# Create Gradio interface
|
| 49 |
-
interface = gr.Interface(fn=
|
| 50 |
-
title="
|
| 51 |
-
description="
|
| 52 |
|
| 53 |
-
# Launch
|
| 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()
|