File size: 1,449 Bytes
60e3a80
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
import gradio as gr
from langchain_community.document_loaders import WebBaseLoader
from mychain import myChain
from myportfolio import myPortfolio
from utils import cleaned_JD_page

def generate_email(url_input, llm, portfolio, cleaned_JD_page):
    try:
        loader = WebBaseLoader([url_input])
        data = cleaned_JD_page(loader.load().pop().page_content)
        portfolio.load_portfolio()
        jobs = llm.extract_jobs_postings(data)
        emails = []
        for job in jobs:
            skills = job.get('skills', [])
            links = portfolio.query_links(skills)
            email = llm.create_email(job, links)
            emails.append(email)
        return '\n\n'.join(emails)
    except Exception as e:
        return f"An Error Occurred: {e}"

def create_gradio_app():
    chain = myChain()
    portfolio = myPortfolio()
    
    # Use gr.Textbox for both inputs and outputs
    url_input = gr.Textbox(label="Enter the JD Page URL")
    email_output = gr.Textbox(label="Generated Cold Email")

    iface = gr.Interface(
        fn=lambda url: generate_email(url, chain, portfolio, cleaned_JD_page),
        inputs=url_input,
        outputs=email_output,
        title="🖋️ cold-email-crafter (by @himanshustwts)",
        description="Generate cold emails based on job descriptions."
    )
    
    iface.launch(share=True)

if __name__ == "__main__":
    create_gradio_app()