-
AI Prativa – Smart Farming Assistant – API Call Code Understanding
FastAPI Call Code Understanding @router.post("/api/chat") async def chat( request: Request, audio: Optional[UploadFile] = File(None), text: Optional[str] = Form(None) ): """ Handle chat requests – supports both audio and text input """ try: # Handle audio input if audio: # Validate file extension file_extension = audio.filename.split('.')[-1].lower() if file_extension not in settings.ALLOWED_EXTENSIONS: raise HTTPException( status_code=400, detail=f"File type not allowed. Allowed types: {settings.ALLOWED_EXTENSIONS}" ) # Save uploaded audio file file_path = os.path.join(settings.UPLOAD_FOLDER, audio.filename) os.makedirs(settings.UPLOAD_FOLDER, exist_ok=True) with open(file_path, "wb") as f: content = await audio.read() f.write(content) # Transcribe audio to text transcription = await speech_service.transcribe_audio(file_path) # Clean up uploaded file if os.path.exists(file_path): os.remove(file_path) return
-
AI Prativa – Smart Farming Assistant – Hugging Face API Key Setup
Smart Farming Assistant – Hugging Face API Key Setup #1 Open The Hugging Face URL https://huggingface.co/ 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
-
AI Prativa – Smart Farming Assistant – OpenAI API Key Setup
Smart Farming Assistant -OpenAI API Key Setup https://platform.openai.com/ API Key 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 Trying Out New API Key #1 – Run this curl command in a terminal to generate a haiku for free using the gpt-5-nano model via the Responses API. curl https://api.openai.com/v1/responses -H "Content-Type: application/json" -H "Authorization: Bearer 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" -d '{ "model": "gpt-5-nano", "input": "write a haiku about ai", "store": true }' #2 – Install the OpenAI Node SDK and execute the code below to generate a haiku for free using the gpt-5-nano model via the Responses API. npm install openai import OpenAI from "openai"; const openai = new OpenAI({ apiKey:
-
AI Prativa -Smart Farming Assistant – Run The Python API Project
Smart Farming Assistant – Running The Python API Step-1: Extract Project cd my-python-api Step-2: Install Dependencies # Create virtual environment python -m venv venv # Activate it source venv/bin/activate # On Windows: venvScriptsactivate # Install packages pip install -r requirements.txt Step-3: Configure API Keys # Copy example file cp .env.example .env # Edit .env and add your keys: # open_ai_key=sk-your-openai-key-here # hugging_face=Bearer hf_your-huggingface-token-here Step-4: Run! # Start the server uvicorn app.main:app – -reload # Or use: python -m app.main Step-5: Visit URL http://localhost:8000 Step-6: Quick API Test Open a new terminal and run the below code to test whether the
-
AI Prativa – Smart Farming Assistant – Project Folder Setup
Smart Farming Assistant – Project Folder Setup my-python-api/ βββ app/ # Main application package β βββ __init__.py # App initialization β βββ main.py # FastAPI app entry point & configuration β β β βββ api/ # API endpoints β β βββ __init__.py β β βββ routes.py # All API routes β β β βββ models/ # Data models (ORM & Pydantic) β β βββ __init__.py β β β βββ services/ # Business logic layer β β βββ __init__.py β β βββ openai_service.py # OpenAI API integration β β βββ audio_service.py # Text-to-Speech (gTTS) β β βββ speech_service.py # Speech-to-Text (HuggingFace)
-

AI Prativa – Smart Farming Assistant – Project Planning
Smart Farming Assistant Project Planning βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ β USER INTERACTION β βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ ↓ ββββββββββββββββββββββββ β Voice or Text Input β ββββββββββββββββββββββββ ↓ βββββββββββββββββββββββββββββββββ β β ββββββΌβββββ ββββββββΌβββββββ β VOICE β β TEXT β ββββββ¬βββββ ββββββββ¬βββββββ β β β 1. Upload audio file β 1. Direct input β 2. Save to 'uploads/' β β 3. Speech-to-Text β β (Hugging Face API) β ββββββββββ¬ββββββββββββββββββββββ β βΌ ββββββββββββββββββββββ β TEXT PROCESSING β ββββββββββββββββββββββ β βΌ ββββββββββββββββββββββ β OpenAI GPT-3.5 β β (Agriculture β β Expert System) β ββββββββββββββββββββββ β βΌ ββββββββββββββββββββββ β AI Response β ββββββββββββββββββββββ β ββββββββββ΄βββββββββ β β βΌ βΌ ββββββββββ ββββββββββββ
