resume-revealer-g / app-g.py
astro21's picture
Upload 8 files
71843ed verified
import gradio as gr
from langchain_community.chat_models import ChatOpenAI
from utils import process_file_with_dedoc, extract_text_from_all_levels, generate_formatted_resume, generate_json_structured_resume
ALLOWED_EXTENSIONS = {"jpg", "jpeg", "png", "docx", "pdf", "html", "doc"}
def allowed_file(filename):
return '.' in filename and filename.rsplit('.', 1)[1].lower() in ALLOWED_EXTENSIONS
def parse_resume(file_info, status):
file_path, file = file_info
filename = file_path.split("/")[-1] # Extract the file name
if not allowed_file(filename):
return "Invalid file type. Allowed file types are: jpg, jpeg, png, docx, pdf, html, doc", None, filename
status.update(f"Processing: {filename}")
# Create instances of the chat model
chat_llm_text = ChatOpenAI(model='gpt-3.5-turbo', temperature=0.0)
chat_llm_json = ChatOpenAI(model='gpt-3.5-turbo', temperature=0.0)
# Read and process the file
text = process_file_with_dedoc(file) # Ensure this is synchronous or adapted for async in Gradio
status.update(f"Extracting text from: {filename}")
text_f = extract_text_from_all_levels(text) # Ensure this is synchronous or adapted for async in Gradio
# Generate parsed resume and parsed JSON resume
status.update(f"Generating formatted resume for: {filename}")
parsed_resume = generate_formatted_resume(text_f, chat_llm_text)
status.update(f"Generating structured JSON resume for: {filename}")
parsed_json_resume = generate_json_structured_resume(text_f, chat_llm_json)
return parsed_resume, parsed_json_resume, filename
# Define the Gradio interface
demo = gr.Interface(
fn=parse_resume,
inputs=[
gr.File(label="Upload your resume"),
gr.StatusTracker()
],
outputs=[
gr.Textbox(label="Formatted Resume"),
gr.JSON(label="Structured JSON Resume"),
gr.Textbox(label="File Name", lines=1)
],
title="Resume Parser",
description="Upload a resume to parse it into formatted text and structured JSON."
)
if __name__ == "__main__":
demo.launch(share=True)