ALL GEN AI CODE
https://www.effectivecpmnetwork.com/pu0i6yqbn9?key=09abbe82535cad4d6bb48e61d3ebb3b4
PDF RAG CHATBOT CODE:
Hp Laptop:
import requests
from pypdf import PdfReader
import faiss
import numpy as np
import os
OLLAMA_URL = "http://localhost:11434/api"
LLM_MODEL = "qwen"
EMBED_MODEL = "nomic-embed-text"
# ---------------------------
# LOAD PDF
# ---------------------------
def load_pdf(file_path):
reader = PdfReader(file_path)
text = ""
for page in reader.pages:
content = page.extract_text()
if content:
text += content
return text
https://www.effectivecpmnetwork.com/pu0i6yqbn9?key=09abbe82535cad4d6bb48e61d3ebb3b4
# ---------------------------
# SPLIT TEXT
# ---------------------------
def split_text(text, chunk_size=500):
chunks = []
for i in range(0, len(text), chunk_size):
chunks.append(text[i:i + chunk_size])
return chunks
# ---------------------------
# GET EMBEDDINGS (FIXED)
# ---------------------------
def get_embedding(text):
response = requests.post(
f"{OLLAMA_URL}/embeddings",
json={
"model": EMBED_MODEL,
"prompt": text
}
)
data = response.json()
# ✅ Handle multiple formats
if "embedding" in data:
return data["embedding"]
elif "data" in data:
return data["data"][0]["embedding"]
else:
raise ValueError(f"Unexpected response: {data}")
# ---------------------------
# CREATE VECTOR DB
# ---------------------------
def create_vector_db(chunks):
print("🔄 Creating embeddings... (this may take time)")
embeddings = [get_embedding(chunk) for chunk in chunks]
dim = len(embeddings[0])
index = faiss.IndexFlatL2(dim)
index.add(np.array(embeddings).astype("float32"))
return index, embeddings
Hp Laptop:
# ---------------------------
# SEARCH
# ---------------------------
def search(query, index, chunks, k=3):
query_embedding = np.array([get_embedding(query)]).astype("float32")
distances, indices = index.search(query_embedding, k)
results = [chunks[i] for i in indices[0]]
return results
https://www.effectivecpmnetwork.com/pu0i6yqbn9?key=09abbe82535cad4d6bb48e61d3ebb3b4
# ---------------------------
# ASK LLM
# ---------------------------
def ask_llm(context, question):
prompt = f"""
You are an AI assistant. Answer ONLY from the context below.
Context:
{context}
Question:
{question}
Answer:
"""
response = requests.post(
f"{OLLAMA_URL}/generate",
json={
"model": LLM_MODEL,
"prompt": prompt,
"stream": False
}
)
return response.json()["response"]
# ---------------------------
# MAIN
# ---------------------------
def main():
print("🤖 Local RAG PDF Chatbot\n")
pdf_path = input("Enter PDF path: ")
# ✅ Validate file
if not os.path.isfile(pdf_path):
print("❌ Invalid file path. Please enter a valid PDF file.")
return
print("📄 Reading PDF...")
text = load_pdf(pdf_path)
print("✂️ Splitting text...")
chunks = split_text(text)
print("🧠 Creating vector database...")
index, _ = create_vector_db(chunks)
print("\n✅ RAG Ready! Type 'exit' to quit.\n")
while True:
query = input("Ask: ")
if query.lower() == "exit":
print("👋 Goodbye!")
break
results = search(query, index, chunks)
context = "\n\n".join(results)
https://www.effectivecpmnetwork.com/pu0i6yqbn9?key=09abbe82535cad4d6bb48e61d3ebb3b4
answer = ask_llm(context, query)
print("\n✅ Answer:\n")
print(answer)
print("\n" + "-" * 50 + "\n")
if name == "main":
main()
Hp Laptop:
2. email code:
import requests
OLLAMA_URL = "http://localhost:11434/api/generate"
MODEL = "llama3"
def generate_email(subject, tone, recipient, purpose):
prompt = f"""
Write a professional email.
Subject: {subject}
Recipient: {recipient}
Purpose: {purpose}
Tone: {tone}
Make it well-structured with greeting, body, and closing.
"""
https://www.effectivecpmnetwork.com/pu0i6yqbn9?key=09abbe82535cad4d6bb48e61d3ebb3b4
response = requests.post(
OLLAMA_URL,
json={
"model": MODEL,
"prompt": prompt,
"stream": False
}
)
return response.json()["response"]
def main():
print("📧 AI Email Generator (LLaMA 3 - Local)\n")
subject = input("Subject: ")
recipient = input("Recipient: ")
purpose = input("Purpose: ")
tone = input("Tone (formal/friendly/professional): ")
email = generate_email(subject, tone, recipient, purpose)
print("\n✅ Generated Email:\n")
print(email)
Hp Laptop:
if name == "main":
main()
https://www.effectivecpmnetwork.com/pu0i6yqbn9?key=09abbe82535cad4d6bb48e61d3ebb3b4
Hp Laptop:
3. ATS SCORE PDF
import requests
from pypdf import PdfReader
OLLAMA_URL = "http://localhost:11434/api/generate"
MODEL = "llama3"
# -----------------------------
# READ RESUME PDF
# -----------------------------
def read_pdf(file_path):
reader = PdfReader(file_path)
text = ""
for page in reader.pages:
content = page.extract_text()
if content:
text += content
return text
# -----------------------------
# GENERATE ATS ANALYSIS
# -----------------------------
def analyze_resume(resume_text, job_desc):
prompt = f"""
You are an ATS (Applicant Tracking System).
https://www.effectivecpmnetwork.com/pu0i6yqbn9?key=09abbe82535cad4d6bb48e61d3ebb3b4
Analyze the resume based on the job description.
Give output in this format:
ATS Score (0-100):
Missing Keywords:
Strengths:
Weaknesses:
Suggestions:
Job Description:
{job_desc}
Resume:
{resume_text}
"""
https://www.effectivecpmnetwork.com/pu0i6yqbn9?key=09abbe82535cad4d6bb48e61d3ebb3b4
response = requests.post(
OLLAMA_URL,
json={
"model": MODEL,
"prompt": prompt,
"stream": False
}
)
return response.json()["response"]
Hp Laptop:
# -----------------------------
# MAIN
# -----------------------------
def main():
print("📄 AI Resume Analyzer (ATS Score)\n")
pdf_path = input("Enter resume PDF path: ")
job_desc = input("Enter job description: ")
print("\n⏳ Reading resume...\n")
resume_text = read_pdf(pdf_path)
print("🧠 Analyzing...\n")
result = analyze_resume(resume_text, job_desc)
print("✅ RESULT:\n")
print(result)
if name == "main":
main()
Hp Laptop:
4. YOUTUBE SUMMERIZER
import requests
from youtube_transcript_api import YouTubeTranscriptApi
OLLAMA_URL = "http://localhost:11434/api/generate"
MODEL = "llama3"
Hp Laptop:
# Extract video ID
def get_video_id(url):
if "v=" in url:
return url.split("v=")[-1]
elif "youtu.be/" in url:
return url.split("youtu.be/")[1].split("?")[0]
def get_transcript(video_id):
api = YouTubeTranscriptApi()
transcript = api.fetch(video_id)
text = " ".join([t.text for t in transcript])
return text
# Summarize using LLM
def summarize(text):
prompt = f"""
Summarize the following YouTube video transcript:
{text[:3000]} # limit text for speed
Give a short and clear summary.
"""
https://www.effectivecpmnetwork.com/pu0i6yqbn9?key=09abbe82535cad4d6bb48e61d3ebb3b4
response = requests.post(
OLLAMA_URL,
json={
"model": MODEL,
"prompt": prompt,
"stream": False
}
)
return response.json()["response"]
# MAIN
def main():
url = input("Enter YouTube URL: ")
video_id = get_video_id(url)
print("⏳ Fetching transcript...")
text = get_transcript(video_id)
print("🧠 Summarizing...")
summary = summarize(text)
https://www.effectivecpmnetwork.com/pu0i6yqbn9?key=09abbe82535cad4d6bb48e61d3ebb3b4
print("\n✅ Summary:\n")
print(summary)
if name == "main":
main()
Hp Laptop:
Hp Laptop:
5. CODE GEN
import requests
OLLAMA_URL = "http://localhost:11434/api/generate"
MODEL = "deepseek-coder:1.3b"
https://www.effectivecpmnetwork.com/pu0i6yqbn9?key=09abbe82535cad4d6bb48e61d3ebb3b4
# -----------------------------
# GENERATE CODE
# -----------------------------
def generate_code(prompt):
full_prompt = f"""
You are an expert programmer.
Generate clean, well-structured code.
Task:
{prompt}
Provide only code output.
"""
response = requests.post(
OLLAMA_URL,
json={
"model": MODEL,
"prompt": full_prompt,
"stream": False
}
)
https://www.effectivecpmnetwork.com/pu0i6yqbn9?key=09abbe82535cad4d6bb48e61d3ebb3b4
return response.json()["response"]
Hp Laptop:
# -----------------------------
# MAIN
# -----------------------------
def main():
print("💻 AI Code Generator (DeepSeek Coder 1.3B)\n")
print("Type 'exit' to quit\n")
while True:
user_prompt = input("Enter your coding task: ")
if user_prompt.lower() == "exit":
print("👋 Goodbye!")
break
if not user_prompt.strip():
print("⚠️ Please enter a valid task\n")
continue
print("\n⏳ Generating code...\n")
code = generate_code(user_prompt)
print("✅ Generated Code:\n")
print(code)
print("\n" + "-" * 50 + "\n")
if name == "main":
main()
Hp Laptop:
Hp Laptop:
6. LANG TRANSLATE
https://www.effectivecpmnetwork.com/pu0i6yqbn9?key=09abbe82535cad4d6bb48e61d3ebb3b4
import requests
OLLAMA_URL = "http://localhost:11434/api/generate"
MODEL = "qwen"
def translate(text, target_lang):
prompt = f"""
Translate the following text into {target_lang}.
Only output translated text. No explanation.
Text:
{text}
"""
Hp Laptop:
response = requests.post(
OLLAMA_URL,
json={
"model": MODEL,
"prompt": prompt,
"stream": False
}
)
return response.json()["response"]
https://www.effectivecpmnetwork.com/pu0i6yqbn9?key=09abbe82535cad4d6bb48e61d3ebb3b4
def main():
print("🌍 AI Translator (Qwen)\n")
while True:
text = input("Enter text (or exit): ")
if text.lower() == "exit":
break
lang = input("Translate to: ")
result = translate(text, lang)
print("\n✅ Translation:\n", result)
if name == "main":
main()
Hp Laptop:
Hp Laptop:
7. WEBSITE SUMMERIZER
Hp Laptop:
import requests
from bs4 import BeautifulSoup
https://www.effectivecpmnetwork.com/pu0i6yqbn9?key=09abbe82535cad4d6bb48e61d3ebb3b4
OLLAMA_URL = "http://localhost:11434/api/generate"
MODEL = "mistral"
# -----------------------------
# FETCH WEBSITE CONTENT
# -----------------------------
def get_website_text(url):
try:
response = requests.get(url)
soup = BeautifulSoup(response.text, "html.parser")
# Remove scripts & styles
for tag in soup(["script", "style"]):
tag.decompose()
text = soup.get_text(separator=" ")
return text[:3000] # limit for LLM
except Exception as e:
return f"Error fetching website: {e}"
# -----------------------------
# ANALYZE USING LLM
# -----------------------------
def analyze_website(content):
prompt = f"""
You are an AI Website Analyzer.
Analyze the website content and provide:
1. Summary
Content:
{content}
ONLY give structured output.
"""
response = requests.post(
OLLAMA_URL,
json={
"model": MODEL,
"prompt": prompt,
"stream": False
}
)
Hp Laptop:
return response.json()["response"]
# -----------------------------
# MAIN
# -----------------------------
def main():
print("🌐 AI Website Analyzer (Mistral)\n")
while True:
url = input("Enter Website URL (or exit): ")
if url.lower() == "exit":
break
print("\n⏳ Fetching website...\n")
content = get_website_text(url)
https://www.effectivecpmnetwork.com/pu0i6yqbn9?key=09abbe82535cad4d6bb48e61d3ebb3b4
print("🧠 Analyzing...\n")
result = analyze_website(content)
print("✅ RESULT:\n")
print(result)
print("\n" + "-" * 50 + "\n")
if name == "main":
main()
Hp Laptop:
https://www.effectivecpmnetwork.com/pu0i6yqbn9?key=09abbe82535cad4d6bb48e61d3ebb3b4

No comments:
Post a Comment