AGENT-3 v1.0 // hf
Naqi Qreatives Neural Extraction Engine
Drag & Drop or Click to attach (PDF/TXT)
import os from fastapi import FastAPI, Request, UploadFile, File, Form, HTTPException from fastapi.responses import HTMLResponse from fastapi.middleware.cors import CORSMiddleware from langchain_groq import ChatGroq import uvicorn import requests from bs4 import BeautifulSoup import io app = FastAPI() # 1. Groq Setup (ApiKey ENV se uthayega) try: llm = ChatGroq(groq_api_key=os.getenv("GROQ_API_KEY"), model_name="llama3-70b-8192") except Exception as e: llm = None print(f"Error initializing Groq: {e}") # 2. CORS (Internal requests ke liye zaruri nahi, lekin safety ke liye) app.add_middleware( CORSMiddleware, allow_origins=["*"], allow_methods=["*"], allow_headers=["*"], ) # 3. Simple Web Scraper Function def simple_scrape(url): try: response = requests.get(url, timeout=10) soup = BeautifulSoup(response.text, 'html.parser') # Sirf main text nikalte hain (headers, paragraphs, lists) text_content = "" for element in soup.find_all(['h1', 'h2', 'h3', 'p', 'li']): text_content += element.get_text() + "\n" return text_content[:5000] # Groq ki context limit ke liye chunking except Exception as e: return f"Error scraping URL: {str(e)}" # --- FRONTEND (Hugging Face Special Edition - No Vercel Needed) --- html_content = """
Naqi Qreatives Neural Extraction Engine
Drag & Drop or Click to attach (PDF/TXT)