Pravincoder commited on
Commit
0f1b5d3
·
verified ·
1 Parent(s): 686e896

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +86 -0
app.py ADDED
@@ -0,0 +1,86 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import logging
2
+ import os
3
+ from pathlib import Path
4
+ from dotenv import load_dotenv
5
+ from crewai import Crew
6
+ from langchain_groq import ChatGroq
7
+ import gradio as gr
8
+ from resume import extract_text_from_file
9
+ from crew import FormFillingAgents, FormFillingTasks
10
+
11
+
12
+ def build_gradio_app():
13
+ """Builds the Gradio interface for the form-filling app."""
14
+ logging.basicConfig(level=logging.INFO)
15
+
16
+ # Define input elements
17
+ resume_input = gr.File(label="Upload Resume", file_types=[".pdf", ".docx", ".txt"])
18
+ job_desc_input = gr.Textbox(label="Job Description", placeholder="Enter job description here")
19
+ questions_input = gr.Textbox(label="Questions", placeholder="Enter questions, separated by commas")
20
+ api_key_input = gr.Textbox(label="GROQ API Key", placeholder="Enter your GROQ API Key")
21
+
22
+ # Define output elements
23
+ answers = gr.Textbox(label="Tailored Answer to the Question Based on Your Resume", interactive=False)
24
+
25
+ # Processing function
26
+ def process_inputs(api_key, resume_input, job_desc, questions):
27
+ try:
28
+ # Debugging
29
+ logging.info("Received API Key, Resume, Job Description, and Questions.")
30
+ logging.info(f"API Key: {api_key}")
31
+ # Save API key to .env file it the user has session active
32
+ if api_key:
33
+ env_path = Path(__file__).parent / ".env"
34
+ with open(env_path, "w") as env_file:
35
+ env_file.write(f"GROQ_API_KEY={api_key}")
36
+ logging.info("API Key saved to .env file.")
37
+ else:
38
+ logging.warning("No API Key provided.")
39
+
40
+ load_dotenv()
41
+
42
+ # Initialize language model
43
+ llm = ChatGroq(
44
+ model="groq/llama-3.1-8b-instant",
45
+ api_key=os.getenv("GROQ_API_KEY"),
46
+ )
47
+ logging.info("Language model initialized successfully.")
48
+
49
+ # Extract text from resume
50
+ resume_text = extract_text_from_file(resume_input)
51
+ logging.info("Resume text extracted.")
52
+
53
+ # Initialize agents and tasks
54
+ agents = FormFillingAgents()
55
+ analysis_agent = agents.resume_analysis_agent(llm)
56
+ qa_agent = agents.question_answering_agent(llm)
57
+ tasks = FormFillingTasks()
58
+ profile_task = tasks.profile_analysis_task(analysis_agent, resume_text, job_desc)
59
+ qa_task = tasks.question_answering_task(qa_agent, questions)
60
+
61
+ # Run Crew pipeline
62
+ crew = Crew(
63
+ agents=[analysis_agent, qa_agent],
64
+ tasks=[profile_task, qa_task],
65
+ verbose=True,
66
+ max_rpm=29,
67
+ )
68
+ results = crew.kickoff()
69
+ logging.info("Pipeline executed successfully.")
70
+ return str(results)
71
+
72
+ except Exception as e:
73
+ logging.error(f"Error during processing: {e}")
74
+ return f"Error during processing: {str(e)}"
75
+ # Gradio interface
76
+ interface = gr.Interface(
77
+ fn=process_inputs,
78
+ inputs=[api_key_input, resume_input, job_desc_input, questions_input],
79
+ outputs=[answers],
80
+ title="Form Filling Assistant",
81
+ description="Upload a resume, provide a job description, input API key, and ask questions to get tailored responses.",
82
+ )
83
+ interface.launch()
84
+
85
+ if __name__ == '__main__':
86
+ build_gradio_app()