husseinelsaadi NourSh2001 commited on
Commit
504b6a7
·
verified ·
1 Parent(s): a0f9750

Upload 3 files (#2)

Browse files

- Upload 3 files (06ec4650d567bad4f899fc2ba2abf72096ea8ed0)


Co-authored-by: Nour Shaito <[email protected]>

chatbot/chatbot.py ADDED
@@ -0,0 +1,77 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # chatbot/chatbot.py
2
+
3
+ from flask import Flask, request, jsonify
4
+ from langchain.text_splitter import RecursiveCharacterTextSplitter
5
+ from sentence_transformers import SentenceTransformer
6
+ import chromadb
7
+ from chromadb.config import Settings
8
+ import openai
9
+ import os
10
+
11
+ # === CONFIG ===
12
+ GROQ_API_KEY = "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"
13
+ GROQ_MODEL = "llama3-8b-8192"
14
+ CHATBOT_TXT_PATH = "./chatbot/chatbot.txt"
15
+
16
+ # === Setup ===
17
+ app = Flask(__name__)
18
+ openai.api_key = GROQ_API_KEY
19
+ openai.api_base = "https://api.groq.com/openai/v1"
20
+
21
+ # === Load and split chatbot.txt ===
22
+ text = open(CHATBOT_TXT_PATH, encoding="utf-8").read()
23
+ splitter = RecursiveCharacterTextSplitter(chunk_size=300, chunk_overlap=100)
24
+ docs = [doc.strip() for doc in splitter.split_text(text)]
25
+
26
+ # === Embed and store in ChromaDB ===
27
+ embedder = SentenceTransformer("all-MiniLM-L6-v2")
28
+ embeddings = embedder.encode(docs, show_progress_bar=True, batch_size=32)
29
+
30
+ client = chromadb.Client(Settings(persist_directory="./chatbot/chroma_db", anonymized_telemetry=False))
31
+ collection = client.get_or_create_collection("chatbot")
32
+ ids = [f"doc_{i}" for i in range(len(docs))]
33
+ collection.add(documents=docs, embeddings=embeddings, ids=ids)
34
+
35
+ # === Core logic ===
36
+ def get_response(query: str) -> str:
37
+ query_embedding = embedder.encode([query])[0]
38
+ results = collection.query(query_embeddings=[query_embedding], n_results=3)
39
+ retrieved_docs = results['documents'][0]
40
+ context = "\n".join(retrieved_docs)
41
+
42
+ system_prompt = (
43
+ "You are a helpful assistant for the Codingo website. "
44
+ "Only answer questions that are directly relevant to the context provided. "
45
+ "If the user asks anything unrelated, politely refuse by saying: "
46
+ "\"I'm only trained to answer questions about the Codingo platform.\""
47
+ )
48
+
49
+ user_prompt = f"Context:\n{context}\n\nQuestion: {query}"
50
+
51
+ completion = openai.ChatCompletion.create(
52
+ model=GROQ_MODEL,
53
+ messages=[
54
+ {"role": "system", "content": system_prompt},
55
+ {"role": "user", "content": user_prompt},
56
+ ],
57
+ max_tokens=200,
58
+ temperature=0.3,
59
+ )
60
+
61
+ return completion['choices'][0]['message']['content'].strip()
62
+
63
+ # === Flask route ===
64
+ @app.route("/chat", methods=["POST"])
65
+ def chat():
66
+ user_input = request.json.get("message", "").strip()
67
+ if not user_input:
68
+ return jsonify({"error": "Empty message"}), 400
69
+
70
+ try:
71
+ reply = get_response(user_input)
72
+ return jsonify({"response": reply})
73
+ except Exception as e:
74
+ return jsonify({"error": str(e)}), 500
75
+
76
+ if __name__ == "__main__":
77
+ app.run(port=5001)
chatbot/chatbot.txt ADDED
@@ -0,0 +1,38 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ INTRODUCTION: Codingo is an AI-driven recruitment platform designed to streamline job applications, candidate screening, and hiring. We aim to make hiring smarter, faster, and fairer through automation and intelligent recommendations.
2
+
3
+ HOW THE PLATFORM WORKS: FOR CANDIDATES: Create a profile with personal and professional details. Upload your resume (PDF or DOC). Add portfolio links (GitHub, LinkedIn, personal website). AI matches you with job postings that suit your skills. Receive instant CV improvement tips. Apply to jobs directly or save for later.
4
+
5
+ HOW THE PLATFORM WORKS: FOR EMPLOYERS: Post job descriptions with required skills and qualifications. Filter and narrow down candidate lists. Review top-matched applicants. Use the chatbot to answer candidate or hiring questions. Get automated screening insights.
6
+
7
+ WHAT MAKES CODINGO SPECIAL: AI that understands both tech and language. Real-time CV feedback. Bias-aware algorithms. Built-in content moderation and chatbot filtering. Tailored for developers, designers, and digital professionals.
8
+
9
+ CV & PORTFOLIO TIPS: Keep resumes under 2 pages. Use action words like "developed", "led", "optimized". Include quantifiable metrics. Tailor your resume to each job. Portfolio should include 3-5 projects with clear documentation.
10
+
11
+ CHATBOT RULES & LIMITATIONS: Only answers Codingo-related questions. Refuses to respond to personal, political, or unrelated queries. Does not provide legal or medical advice. Typo tolerance for job-related keywords and tech terms. Responds based on platform content only.
12
+
13
+ AI MATCHING ENGINE: Uses NLP to match skills. Cosine similarity for job description and profile comparison. Named Entity Recognition for understanding job titles. Intent detection for distinguishing job search vs application help.
14
+
15
+ SUPPORTED JOB TYPES: Frontend Developer, Backend Developer, Full-Stack Developer, Data Scientist, UI/UX Designer, DevOps Engineer, Product Manager, QA Engineer, Mobile Developer, AI/ML Engineer.
16
+
17
+ CONTENT POLICY: Professional, unbiased, safe, and aligned with the brand voice. No profanity, hate speech, or collection of personal data. No controversial topics in responses.
18
+
19
+ SECURITY & PRIVACY: User data is encrypted and stored securely. No data used for advertising. You can delete your data anytime via profile settings.
20
+
21
+ FREQUENTLY ASKED QUESTIONS:
22
+ Q: How can I improve my match score?
23
+ A: Update your profile with accurate skills and project links. Add keywords from job descriptions.
24
+
25
+ Q: Can I use the chatbot to write my resume?
26
+ A: The chatbot provides tips, but doesn't generate full resumes.
27
+
28
+ Q: What if I see an error in my profile?
29
+ A: Edit your profile at any time. For technical issues, contact support.
30
+
31
+ Q: Is Codingo free?
32
+ A: Profile creation and job applications are free. Premium features may be offered for advanced analytics.
33
+
34
+ CONTACT & SUPPORT:
35
36
+ Website: https://www.codingo.ai
37
+ LinkedIn: https://linkedin.com/company/codingo
38
+ Help Center: https://www.codingo.ai/help
chatbot/requirements.txt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ flask
2
+ flask-cors
3
+ groq