Spaces:
Runtime error
Runtime error
Update app.py
Browse files1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768import gradio as grimport refrom docx import Document # Use python-docx to read DOCX filesfrom PyPDF2 import PdfFileReader # Import PdfFileReader from PyPDF2# Function to extract text from a PDF filedef extract_text_from_pdf(pdf_file):text = ""pdf = PdfFileReader(pdf_file)for page_num in range(pdf.getNumPages()):page = pdf.getPage(page_num)text += page.extractText()return text# Function to extract text from a DOCX filedef extract_text_from_docx(docx_file):doc = Document(docx_file)text = "\n".join([para.text for para in doc.paragraphs])return text# Function to extract information from a resumedef extract_info_from_resume(resume_path):if resume_path.name.endswith('.pdf'):text = extract_text_from_pdf(resume_path)elif resume_path.name.endswith('.docx'):text = extract_text_from_docx(resume_path)else:raise ValueError("Unsupported file format. Only PDF and DOCX are supported.")# Define regular expressions to extract informationname_pattern = r"([A-Z][a-z]+(?: [A-Z][a-z]+)+)"email_pattern = r"[\w\.-]+@[\w\.-]+"phone_pattern = r"(\(?\d{3}\)?[-.\s]?\d{3}[-.\s]?\d{4})"name = re.search(name_pattern, text)email = re.search(email_pattern, text)phone = re.search(phone_pattern, text)if name:name = name.group()else:name = "Name not found"if email:email = email.group()else:email = "Email not found"if phone:phone = phone.group()else:phone = "Phone number not found"extracted_info = {"Name": name,"Email": email,"Phone": phone,}return extracted_info# Define a Gradio interfaceiface = gr.Interface(fn=extract_info_from_resume,inputs=gr.inputs.File(type="file"),outputs="json")# Deploy the Gradio interfaceiface.launch(share=True)
app.py+68