krishbakshi commited on
Commit
ef7d644
·
verified ·
1 Parent(s): a645179

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +103 -0
app.py ADDED
@@ -0,0 +1,103 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import os
3
+ import utils
4
+ import config
5
+ import pandas as pd
6
+
7
+ def output(file, text1, text2, text3, text4, text5, text6, progress: gr.Progress = gr.Progress(track_tqdm=True)):
8
+
9
+ output_text = ""
10
+
11
+ if file is None:
12
+ return gr.Error("No file uploaded.")
13
+
14
+ file_path = file.name
15
+ structured_data = utils.process_resume(file_path)
16
+ if structured_data is None:
17
+ return gr.Error("Unsupported file type.")
18
+
19
+ prompt = f"""
20
+ {{
21
+ "Hiring Manager's Name": "{text1}",
22
+ "Company Name": "{text2}",
23
+ "Industry/Field": "{text3}",
24
+ "Specific Projects, Innovations, or Company Achievements": "{text4}",
25
+ "Specific Skills or Tools Relevant to the Job": "{text5}",
26
+ "Specific Roles, Teams, or Projects at the Company": "{text6}",
27
+ "resume": {structured_data}
28
+ }}
29
+ """
30
+ progress(0.5)
31
+ output_text = utils.generate_email(prompt)
32
+ progress(1)
33
+
34
+ return output_text, output_text
35
+
36
+ def bulk_output(excel, pdf, progress: gr.Progress = gr.Progress(track_tqdm=True)):
37
+ if excel is None:
38
+ return gr.Error("No file uploaded.")
39
+
40
+ excel_path = excel.name
41
+ df = pd.read_excel(excel_path)
42
+
43
+ if pdf is None:
44
+ return gr.Error("No file uploaded.")
45
+
46
+ file_path = pdf.name
47
+ structured_data = utils.process_resume(file_path)
48
+ if structured_data is None:
49
+ return gr.Error("Unsupported file type.")
50
+
51
+ for index, row in df.iterrows():
52
+ prompt = f"""
53
+ {{
54
+ "Hiring Manager's Name": "{row['Hiring Managers Name']}",
55
+ "Company Name": "{row['Company Name']}",
56
+ "Industry/Field": "{row['Industry/Field']}",
57
+ "Specific Projects, Innovations, or Company Achievements": "{row['Specific Projects, Innovations, or Company Achievements']}",
58
+ "Specific Skills or Tools Relevant to the Job": "{row['Specific Skills or Tools Relevant to the Job']}",
59
+ "Specific Roles, Teams, or Projects at the Company": "{row['Specific Roles, Teams, or Projects at the Company']}",
60
+ "resume": {structured_data}
61
+ }}
62
+ """
63
+
64
+ email = utils.generate_email(prompt)
65
+ config.write_email(row['Hiring Manager\'s Name'], row['Company Name'], email)
66
+ progress(index + 1, len(df))
67
+
68
+ return "Emails have been drafted and saved as Word documents."
69
+
70
+ with gr.Blocks() as demo:
71
+ with gr.Tabs():
72
+ with gr.TabItem("Single Email"):
73
+ with gr.Row():
74
+ with gr.Column(scale=0.5):
75
+ text1 = gr.Textbox(label="Hiring Manager's Name")
76
+ text2 = gr.Textbox(label="Company Name")
77
+ text3 = gr.Textbox(label="Industry/Field")
78
+ text4 = gr.Textbox(label="Specific Projects, Innovations, or Company Achievements")
79
+ text5 = gr.Textbox(label="Specific Skills or Tools Relevant to the Job")
80
+ text6 = gr.Textbox(label="Specific Roles, Teams, or Projects at the Company")
81
+ submit_btn = gr.Button("Submit")
82
+ with gr.Column(scale=0.5):
83
+ pdf_input = gr.File(label="Upload PDF", file_types=[".pdf", ".docx"], interactive=True, scale=1)
84
+ output_box = gr.Textbox(label="Output", lines=10, autoscroll=True)
85
+ write_btn = gr.Button("Draft Email")
86
+
87
+
88
+ state = gr.State()
89
+ submit_btn.click(output, inputs=[pdf_input, text1, text2, text3, text4, text5, text6], outputs=[output_box, state])
90
+ write_btn.click(config.write_email, inputs=[text1, text2, state])
91
+
92
+ with gr.TabItem("Batch Email"):
93
+ with gr.Row():
94
+ with gr.Column(scale=0.5):
95
+ pdf_input = gr.File(label="Upload PDF", file_types=[".pdf", ".docx"], interactive=True, scale=1)
96
+ excel_input = gr.File(label="Upload Excel", file_types=[".xlsx"], interactive=True, scale=1)
97
+ submit_btn = gr.Button("Submit and Draft")
98
+ with gr.Column(scale=0.5):
99
+ output_box = gr.Textbox(label="Output", lines=10, autoscroll=True)
100
+
101
+ submit_btn.click(bulk_output, inputs=[excel_input,pdf_input], outputs=[output_box])
102
+
103
+ demo.launch()