Download AgenticControl/description_com_profile.py from Asad999/Texbase: direct link, hf CLI and curl.
- Browser
- Download file 4.28 kB
-
https://huggingface.co/spaces/Asad999/Texbase/resolve/main/AgenticControl/description_com_profile.py
- Command line
-
hf download hf://spaces/Asad999/Texbase/AgenticControl/description_com_profile.py
-
curl -L -o description_com_profile.py https://huggingface.co/spaces/Asad999/Texbase/resolve/main/AgenticControl/description_com_profile.py
4.28 kB
| import requests | |
| import google.generativeai as genai | |
| import os | |
| from dotenv import load_dotenv | |
| # ββ Configuration ββββββββββββββββββββββββββββββββββββββββββββββββββββββββ | |
| # In a real app, load these from your .env file | |
| ROOT_DIR = os.environ.get('WORKSPACE_ROOT', '.') | |
| env_address = os.path.join(ROOT_DIR, 'backend/.env') | |
| load_dotenv(dotenv_path=env_address) | |
| # Now it will successfully find your keys! | |
| GEMINI_API_KEY = os.environ.get("GEMINI_API_KEY") | |
| JINA_API_KEY = os.environ.get("JINA_API_KEY") | |
| genai.configure(api_key=GEMINI_API_KEY) | |
| def scrape_website_to_markdown(url: str) -> str: | |
| """ | |
| Uses Jina Reader API to cleanly extract text from any URL. | |
| It automatically strips out ads, navbars, and messy HTML. | |
| """ | |
| print(f"π΅οΈββοΈ Scraping {url}...") | |
| jina_url = f"https://r.jina.ai/{url}" | |
| headers = { | |
| # This passes your API key securely to Jina's servers | |
| "Authorization": f"Bearer {JINA_API_KEY}", | |
| "X-Retain-Images": "none" | |
| } | |
| response = requests.get(jina_url, headers=headers) | |
| if response.status_code == 200: | |
| return response.text | |
| else: | |
| raise Exception(f"Failed to scrape website. Status code: {response.status_code}\nResponse: {response.text}") | |
| def generate_interview_answer(company_text: str, company_website: str, max_chars: int = 10000) -> str: | |
| """ | |
| Feeds the scraped text into the LLM with a highly specific prompt. | |
| Safely truncates the text to avoid API Quota limit errors. | |
| """ | |
| # π THE FIX: Chop off the excess text | |
| if len(company_text) > max_chars: | |
| print(f"βοΈ Truncating scraped text from {len(company_text)} to {max_chars} characters...") | |
| company_text = company_text[:max_chars] | |
| print("π§ Synthesizing data and drafting answer...") | |
| # Initialize the model | |
| model = genai.GenerativeModel('gemini-flash-lite-latest') | |
| prompt = f""" | |
| You are an intelligent, well-prepared job bot for {company_website}. | |
| I am going to provide you with the scraped text from their official website. | |
| Based ONLY on this text, I want you to answer the classic question: | |
| "What things company working on and what is their mission? What is their focus and what is there vision?" | |
| Guidelines for your answer: | |
| 1. Keep it conversational, confident, and professional (around 3-4 short paragraphs). | |
| 2. Identify their core product/service and who their target audience is. | |
| 3. Highlight their overarching mission or the main problem they are trying to solve. | |
| 4. Mention any recent milestones, unique features, or company values explicitly stated in the text. | |
| 5. Do not hallucinate external information. If a detail isn't in the text, don't invent it. | |
| Here is the company website text: | |
| ----------------------------------- | |
| {company_text} | |
| """ | |
| response = model.generate_content(prompt) | |
| return response.text | |
| # ββ Execution ββββββββββββββββββββββββββββββββββββββββββββββββββββββββ | |
| # if __name__ == "__main__": | |
| # # Example Target | |
| # target_url = "https://www.anthropic.com" # Try changing this to another company! | |
| # company_name = "Anthropic" | |
| # try: | |
| # # Step 1: Get the data | |
| # raw_markdown = scrape_website_to_markdown(target_url) | |
| # # π NEW: Print the exact text pulled by the scraper | |
| # print("\n" + "="*50) | |
| # print("π RAW SCRAPED DATA (From Jina):") | |
| # print("="*50 + "\n") | |
| # print(raw_markdown) | |
| # print("\n" + "="*50 + "\n") | |
| # # Step 2: Generate the answer | |
| # answer = generate_interview_answer(raw_markdown, company_name) | |
| # # Step 3: Output | |
| # print("\n==========================================") | |
| # print(f"ποΈ INTERVIEW QUESTION: What do you know about {company_name}?") | |
| # print("==========================================\n") | |
| # print(answer) | |
| # except Exception as e: | |
| # print(f"β An error occurred: {e}") |