PYTHON #6
Browse filesFiles changed (4)
- .env+5-2
- model/Modelfile → ModelfileRenamed
- app.py+269-135
- requirements.txt+2-1
1234MODEL_NAME=adibrino/LAPOR-AIALLOWED_ORIGINS=https://lalim.vercel.app,http://localhost:8000,http://127.0.0.1:8000SERVICE_CODES_MAP={"DPRKPCK": "Perumahan Rakyat, Kawasan Permukiman dan Cipta Karya", "DPUBM": "Pekerjaan Umum Bina Marga", "DPUSDA": "Pekerjaan Umum Sumber Daya Air", "DLH": "Lingkungan Hidup", "DINSOS": "Sosial", "BPBD": "Penanggulangan Bencana Daerah", "DISHUB": "Perhubungan", "DINKES": "Kesehatan", "SATPOLPP": "Satuan Polisi Pamong Praja", "DISKOMINFO": "Komunikasi dan Informatika", "DISNAKERTRANS": "Tenaga Kerja dan Transmigrasi", "DIPERTAKP": "Pertanian dan Ketahanan Pangan", "DISNAK": "Peternakan", "DKP": "Kelautan dan Perikanan", "DINDIK": "Pendidikan", "DISBUDPAR": "Kebudayaan dan Pariwisata", "DISPERINDAG": "Perindustrian dan Perdagangan", "DPMPTSP": "Penanaman Modal dan Pelayanan Terpadu Satu Pintu", "DISKOPUKM": "Koperasi, Usaha Kecil dan Menengah", "DISPORA": "Kepemudaan dan Olahraga", "DISPERPUSIP": "Perpustakaan dan Kearsipan", "BAPPEDA": "Perencanaan Pembangunan Daerah", "BAPENDA": "Pajak dan Pendapatan Daerah", "DP3AK": "Pemberdayaan Perempuan, Perlindungan Anak dan Kependudukan"}IS_PRODUCTION=false1234567MODEL_NAME=adibrino/LAPOR-AI:latestGEMINI_MODELS="gemini-2.5-flash,gemini-2.5-flash-lite,gemini-2.0-flash,gemini-2.0-flash-lite"GEMINI_API_KEY=AIzaSyCx1MfYMEH_R_o_lqo1D8pwfUERZK8KVuMALLOWED_ORIGINS=https://lalim.vercel.app,http://localhost:8000,http://127.0.0.1:8000SERVICE_CODES_MAP={"DPRKPCK": "Perumahan Rakyat, Kawasan Permukiman dan Cipta Karya", "DPUBM": "Pekerjaan Umum Bina Marga", "DPUSDA": "Pekerjaan Umum Sumber Daya Air", "DLH": "Lingkungan Hidup", "DINSOS": "Sosial", "BPBD": "Penanggulangan Bencana Daerah", "DISHUB": "Perhubungan", "DINKES": "Kesehatan", "SATPOLPP": "Satuan Polisi Pamong Praja", "DISKOMINFO": "Komunikasi dan Informatika", "DISNAKERTRANS": "Tenaga Kerja dan Transmigrasi", "DIPERTAKP": "Pertanian dan Ketahanan Pangan", "DISNAK": "Peternakan", "DKP": "Kelautan dan Perikanan", "DINDIK": "Pendidikan", "DISBUDPAR": "Kebudayaan dan Pariwisata", "DISPERINDAG": "Perindustrian dan Perdagangan", "DPMPTSP": "Penanaman Modal dan Pelayanan Terpadu Satu Pintu", "DISKOPUKM": "Koperasi, Usaha Kecil dan Menengah", "DISPORA": "Kepemudaan dan Olahraga", "DISPERPUSIP": "Perpustakaan dan Kearsipan", "BAPPEDA": "Perencanaan Pembangunan Daerah", "BAPENDA": "Pajak dan Pendapatan Daerah", "DP3AK": "Pemberdayaan Perempuan, Perlindungan Anak dan Kependudukan"}IS_PRODUCTION=falseGEMINI_SYSTEM_INSTRUCTION='Kamu adalah asisten AI backend untuk aplikasi pengaduan warga (Smart City).\nTugasmu adalah menganalisis input laporan warga (Deskripsi, Lokasi, dan Deskripsi Visual Gambar/Video) lalu mengklasifikasikannya ke dalam format JSON yang ketat.\n\n### 1. REFERENSI MAPPING KATEGORI & KODE DINAS (WAJIB PATUH):\nGunakan daftar ini untuk menentukan "category" dan "service_code". Jangan membuat kategori baru di luar daftar ini.\n\n- "Perumahan Rakyat, Kawasan Permukiman dan Cipta Karya" => DPRKPCK\n- "Pekerjaan Umum Bina Marga" => DPUBM\n- "Pekerjaan Umum Sumber Daya Air" => DPUSDA\n- "Lingkungan Hidup" => DLH\n- "Sosial" => DINSOS\n- "Penanggulangan Bencana Daerah" => BPBD\n- "Perhubungan" => DISHUB\n- "Kesehatan" => DINKES\n- "Satuan Polisi Pamong Praja" => SATPOLPP\n- "Komunikasi dan Informatika" => DISKOMINFO\n- "Tenaga Kerja dan Transmigrasi" => DISNAKERTRANS\n- "Pertanian dan Ketahanan Pangan" => DIPERTAKP\n- "Peternakan" => DISNAK\n- "Kelautan dan Perikanan" => DKP\n- "Pendidikan" => DINDIK\n- "Kebudayaan dan Pariwisata" => DISBUDPAR\n- "Perindustrian dan Perdagangan" => DISPERINDAG\n- "Penanaman Modal dan Pelayanan Terpadu Satu Pintu" => DPMPTSP\n- "Koperasi, Usaha Kecil dan Menengah" => DISKOPUKM\n- "Kepemudaan dan Olahraga" => DISPORA\n- "Perpustakaan dan Kearsipan" => DISPERPUSIP\n- "Perencanaan Pembangunan Daerah" => BAPPEDA\n- "Pajak dan Pendapatan Daerah" => BAPENDA\n- "Pemberdayaan Perempuan, Perlindungan Anak dan Kependudukan" => DP3AK\n\n### 2. LOGIKA PRIORITAS (PriorityEnum):\n- "high": Bahaya nyawa, kecelakaan, banjir besar, kebakaran, kekerasan fisik, atau kerusakan infrastruktur vital total.\n- "medium": Mengganggu aktivitas tapi tidak mematikan (macet, jalan berlubang sedang, sampah menumpuk, lampu jalan mati).\n- "low": Bersifat kosmetik, saran, pertanyaan administrasi, atau gangguan ringan.\n\n### 3. ATURAN OUTPUT:\nHanya berikan output JSON mentah. Jangan ada teks pembuka/penutup.\nFormat JSON wajib: { "title": string, "category": string, "priority": string, "service_code": string }'
3 unmodified lines45678910111213142 unmodified lines1718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616 unmodified lines6869707172737475761 unmodified line787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172183 unmodified linesimport jsonimport timeimport subprocessimport threadingimport shutilfrom typing import List, Any, Dict, Unionfrom fastapi import FastAPI, UploadFile, File, Formfrom fastapi.responses import JSONResponse, Responsefrom fastapi.middleware.cors import CORSMiddlewareimport uvicorn2 unmodified linesimport ollamaimport spaces # type: ignoreimport gradio as grload_dotenv()ALLOWED_ORIGINS_RAW: str = os.getenv("ALLOWED_ORIGINS", "*")MODEL_NAME: str = os.getenv("MODEL_NAME") or "adibrino/LAPOR-AI"IS_PRODUCTION: str = os.getenv("IS_PRODUCTION", "false")SERVICE_MAP_STR = os.getenv("SERVICE_CODES_MAP", "{}")SERVICE_MAP = json.loads(SERVICE_MAP_STR)ALLOWED_ORIGINS = ["*"] if ALLOWED_ORIGINS_RAW == "*" else [origin.strip() for origin in ALLOWED_ORIGINS_RAW.split(",")]print(f"ALLOWED_ORIGINS: {ALLOWED_ORIGINS}")print(f"MODEL_NAME: {MODEL_NAME}")def setup_ollama():print("Checking Ollama setup...")if not shutil.which("ollama"):print("Ollama not found. Installing...")subprocess.run("curl -fsSL https://ollama.com/install.sh | sh", shell=True, check=True)def run_server():print("Starting Ollama Serve...")subprocess.Popen(["ollama", "serve"])t = threading.Thread(target=run_server, daemon=True)t.start()print("Waiting for Ollama to spin up...")time.sleep(5)print(f"Pulling Model: {MODEL_NAME}...")try:subprocess.run(["ollama", "pull", MODEL_NAME], check=True)print("Model pulled successfully.")except Exception as e:print(f"Error pulling model: {e}")setup_ollama()app = FastAPI()6 unmodified lines)def process_image_to_base64(image_bytes: bytes) -> Union[str, None]:try:img = Image.open(io.BytesIO(image_bytes))img = img.convert('RGB')buffered = io.BytesIO()img.save(buffered, format="JPEG")return base64.b64encode(buffered.getvalue()).decode('utf-8')1 unmodified lineprint(f"Error processing image: {e}")return None@spaces.GPU(duration=60)def run_inference(report_text: str, base64_images: List[str]) -> Dict[str, Any]:print("Starting GPU Inference...")try:ollama.show(MODEL_NAME)except Exception:print("Model not found in GPU context, pulling again...")subprocess.run(["ollama", "pull", MODEL_NAME], check=True)response: Any = ollama.chat( # type: ignoremodel=MODEL_NAME,messages=[{'role': 'user','content': report_text,'images': base64_images if base64_images else None # type: ignore}],format='json',options={'temperature': 0.1})if isinstance(response, dict):return response # type: ignorereturn dict(response)@app.get("/")def health_check():return Response("Python Backend is running.")@app.post("/api/analyze")async def analyze( # type: ignorereport: str = Form(...),images: List[UploadFile] = File(...)):try:if not report or len(report) < 10:return JSONResponse(status_code=400,content={"status": "error", "message": "Deskripsi laporan wajib diisi minimal 10 karakter."})if not images:return JSONResponse(status_code=400,content={"status": "error", "message": "Wajib melampirkan minimal 1 foto bukti."})base64_images: List[str] = []for img_file in images:content = await img_file.read()if len(content) > 0:b64 = process_image_to_base64(content)if b64:base64_images.append(b64)if not base64_images:return JSONResponse(status_code=400,content={"status": "error", "message": "File gambar tidak valid/corrupt."})max_retries = 3last_exception = Noneprint("Report Text:", report)for attempt in range(max_retries):try:print(f"Attempting AI Analysis... ({attempt + 1}/{max_retries})")response_raw = run_inference(report, base64_images)if 'message' not in response_raw or 'content' not in response_raw['message']:raise ValueError("Empty response structure from AI")content_str = response_raw['message']['content']ai_content = json.loads(content_str)required_keys = ["title", "category", "priority", "service_code"]missing_keys = [key for key in required_keys if key not in ai_content]if missing_keys:raise ValueError(f"Missing keys in JSON: {missing_keys}")if not str(ai_content["title"]).strip():raise ValueError("AI returned empty title")service_code = ai_content["service_code"]if service_code not in SERVICE_MAP:raise ValueError(f"Invalid service_code: {service_code}. Not found in SERVICE_MAP.")expected_category = SERVICE_MAP[service_code]if ai_content["category"] != expected_category:raise ValueError(f"Category mismatch. Got '{ai_content['category']}', expected '{expected_category}' for code {service_code}")priority = str(ai_content["priority"]).lower()if priority not in ['high', 'medium', 'low']:raise ValueError(f"Invalid priority: {priority}")ai_content["priority"] = prioritydata = { # type: ignore"status": "success","data": ai_content,"meta": {"model": MODEL_NAME,'processing_time_sec': (response_raw.get("total_duration", 0)) / 1e9,"images_analyzed": len(base64_images),"attempts": attempt + 1}}print("AI Success")print(json.dumps(data, indent=2, ensure_ascii=True))return data # type: ignoreexcept Exception as e:print(f"Attempt {attempt + 1} failed: {str(e)}")last_exception = etime.sleep(1)continuereturn JSONResponse(status_code=500,content={"status": "error", "message": f"AI Failed: {str(last_exception)}"})except Exception as e:raise eif __name__ == "__main__":with gr.Blocks() as demo:gr.Markdown("# LAPOR AI API Backend")gr.Markdown("This space hosts the API at `/api/analyze`.")gr.Markdown(f"**Model:** {MODEL_NAME}")app = gr.mount_gradio_app(app, demo, path="/") # type: ignore3 unmodified lines45678910111213142 unmodified lines1718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475766 unmodified lines8384858687888990911 unmodified line939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523 unmodified linesimport jsonimport timeimport subprocessimport threading # type: ignoreimport shutil # type: ignorefrom typing import List, Any, Dict, Union, Optionalfrom fastapi import FastAPI, UploadFile, File, Form, HTTPExceptionfrom fastapi.responses import JSONResponse, Responsefrom fastapi.middleware.cors import CORSMiddlewareimport uvicorn2 unmodified linesimport ollamaimport spaces # type: ignoreimport gradio as grimport google.generativeai as genaiload_dotenv()ALLOWED_ORIGINS_RAW: Optional[str] = os.getenv("ALLOWED_ORIGINS")MODEL_NAME: Optional[str] = os.getenv("MODEL_NAME")GEMINI_API_KEY: Optional[str] = os.getenv("GEMINI_API_KEY")GEMINI_MODELS_RAW: Optional[str] = os.getenv("GEMINI_MODELS")SERVICE_MAP_STR = os.getenv("SERVICE_CODES_MAP", "{}")SERVICE_MAP = json.loads(SERVICE_MAP_STR)GEMINI_SYSTEM_INSTRUCTION = os.getenv("GEMINI_SYSTEM_INSTRUCTION", "{}")ALLOWED_ORIGINS = ["*"] if ALLOWED_ORIGINS_RAW == "*" else [origin.strip() for origin in ALLOWED_ORIGINS_RAW.split(",")] # type: ignoreGEMINI_MODEL_LIST: List[str] = [model.strip() for model in GEMINI_MODELS_RAW.split(',')] if GEMINI_MODELS_RAW else []print(f"ALLOWED_ORIGINS: {ALLOWED_ORIGINS}")print(f"LOCAL_MODEL_NAME: {MODEL_NAME}")print(f"GEMINI_MODELS: {GEMINI_MODEL_LIST}")# def setup_ollama():# print("Checking Ollama setup...")# if not shutil.which("ollama"):# print("Ollama not found. Installing...")# subprocess.run("curl -fsSL https://ollama.com/install.sh | sh", shell=True, check=True)# def run_server():# print("Starting Ollama Serve...")# subprocess.Popen(["ollama", "serve"])# t = threading.Thread(target=run_server, daemon=True)# t.start()# print("Waiting for Ollama to spin up...")# time.sleep(5)# print(f"Pulling Model: {MODEL_NAME}...")# try:# subprocess.run(["ollama", "pull", MODEL_NAME], check=True) # type: ignore# print("Model pulled successfully.")# except Exception as e:# print(f"Error pulling model: {e}")# setup_ollama()if GEMINI_API_KEY:try:genai.configure(api_key=GEMINI_API_KEY) # type: ignoreprint("Gemini client configured successfully.")except Exception as e:raise EnvironmentError(f"Error configuring Gemini: {e}")else:raise EnvironmentError("Warning: GEMINI_API_KEY not found. The /api/analyze/gemini endpoint and fallback will be unavailable.")app = FastAPI()6 unmodified lines)def process_image_to_base64(image_bytes: bytes) -> Union[str, None]:"""Converts image bytes to a base64 encoded string."""try:img = Image.open(io.BytesIO(image_bytes)).convert('RGB')buffered = io.BytesIO()img.save(buffered, format="JPEG")return base64.b64encode(buffered.getvalue()).decode('utf-8')1 unmodified lineprint(f"Error processing image: {e}")return Noneasync def process_uploaded_files(images: List[UploadFile]) -> Dict[str, List[Any]]:"""Reads uploaded files and converts them to bytes and base64 strings."""if not images:raise HTTPException(status_code=400, detail="Wajib melampirkan minimal 1 foto bukti.")image_bytes_list: List[bytes] = []base64_images: List[str] = []for img_file in images:content = await img_file.read()if len(content) > 0:image_bytes_list.append(content)b64 = process_image_to_base64(content)if b64:base64_images.append(b64)if not base64_images:raise HTTPException(status_code=400, detail="File gambar tidak valid atau corrupt.")return {"bytes": image_bytes_list, "b64": base64_images}def validate_ai_output(ai_content: Dict[str, Any]) -> Dict[str, Any]:"""Validates the JSON output from an AI model against the required structure and values."""required_keys = ["title", "category", "priority", "service_code"]missing_keys = [key for key in required_keys if key not in ai_content]if missing_keys:raise ValueError(f"Missing keys in AI JSON response: {', '.join(missing_keys)}")if not str(ai_content.get("title", "")).strip():raise ValueError("AI returned an empty title")service_code = ai_content["service_code"]if service_code not in SERVICE_MAP:raise ValueError(f"Invalid service_code '{service_code}'. Not found in service map.")expected_category = SERVICE_MAP[service_code]if ai_content["category"] != expected_category:raise ValueError(f"Category mismatch for code {service_code}. Got '{ai_content['category']}', expected '{expected_category}'")priority = str(ai_content["priority"]).lower()if priority not in ['high', 'medium', 'low']:raise ValueError(f"Invalid priority value: '{priority}'")ai_content["priority"] = priorityreturn ai_content@spaces.GPU(duration=60)def run_local_inference(report_text: str, base64_images: List[str]) -> Dict[str, Any]:"""Runs inference using the local Ollama model."""print("Starting Local GPU Inference...")try:ollama.show(MODEL_NAME) # type: ignoreexcept Exception:print("Model not found in GPU context, pulling again...")subprocess.run(["ollama", "pull", MODEL_NAME], check=True) # type: ignoreresponse = ollama.chat( # type: ignoremodel=MODEL_NAME, # type: ignoremessages=[{'role': 'user','content': report_text,'images': base64_images,}],format='json',options={'temperature': 0.1})return response # type: ignoredef run_gemini_inference(report_text: str, image_bytes_list: List[bytes], model_name: str) -> Dict[str, Any]:"""Runs inference using the Google Gemini model."""print(f"Starting Gemini Inference with model: {model_name}...")if not GEMINI_API_KEY:raise ConnectionError("GEMINI_API_KEY is not configured.")model = genai.GenerativeModel(model_name, system_instruction=GEMINI_SYSTEM_INSTRUCTION) # type: ignorepil_images = [Image.open(io.BytesIO(content)) for content in image_bytes_list]response = model.generate_content([report_text, *pil_images], generation_config={"response_mime_type": "application/json"}) # type: ignoreai_content = json.loads(response.text)return ai_content@app.get("/")def health_check():return Response("Python Backend is running.")@app.post("/api/analyze/local")async def analyze_local(report: str = Form(...), images: List[UploadFile] = File(...)): # type: ignore"""Endpoint to analyze a report using only the local Ollama model."""if not report or len(report) < 10:raise HTTPException(status_code=400, detail="Deskripsi laporan wajib diisi minimal 10 karakter.")processed_images = await process_uploaded_files(images)base64_images = processed_images["b64"]try:response_raw = run_local_inference(report, base64_images)if 'message' not in response_raw or 'content' not in response_raw['message']:raise ValueError("Empty or invalid response structure from local AI")ai_content = validate_ai_output(json.loads(response_raw['message']['content']))return { # type: ignore"status": "success","data": ai_content,"meta": {"model": MODEL_NAME,'processing_time_sec': (response_raw.get("total_duration", 0)) / 1e9,"images_analyzed": len(base64_images),}}except Exception as e:print(f"Local analysis failed: {str(e)}")raise HTTPException(status_code=500, detail=f"Local AI Failed: {str(e)}")@app.post("/api/analyze/gemini")async def analyze_gemini(report: str = Form(...), images: List[UploadFile] = File(...)): # type: ignore"""Endpoint to analyze a report using only the Gemini model."""if not report or len(report) < 10:raise HTTPException(status_code=400, detail="Deskripsi laporan wajib diisi minimal 10 karakter.")processed_images = await process_uploaded_files(images)image_bytes_list = processed_images["bytes"]if not GEMINI_MODEL_LIST:raise HTTPException(status_code=501, detail="No Gemini models configured in the environment.")primary_gemini_model = GEMINI_MODEL_LIST[0]try:start_time = time.time()ai_content = validate_ai_output(run_gemini_inference(report, image_bytes_list, primary_gemini_model))end_time = time.time()return { # type: ignore"status": "success","data": ai_content,"meta": {"model": primary_gemini_model,'processing_time_sec': end_time - start_time,"images_analyzed": len(image_bytes_list),}}except Exception as e:print(f"Gemini analysis failed: {str(e)}")raise HTTPException(status_code=500, detail=f"Gemini AI Failed: {str(e)}")@app.post("/api/analyze")async def analyze_with_fallback(report: str = Form(...), images: List[UploadFile] = File(...)): # type: ignore"""Main analysis endpoint. Tries the local model up to 3 times.If it fails, it falls back to the Gemini model."""if not report or len(report) < 10:raise HTTPException(status_code=400, detail="Deskripsi laporan wajib diisi minimal 10 karakter.")processed_images = await process_uploaded_files(images)base64_images = processed_images["b64"] # type: ignoreimage_bytes_list = processed_images["bytes"]last_local_exception = Nonelast_gemini_exception = None# max_local_retries = 3 # type: ignore# for attempt in range(max_local_retries):# try:# print(f"Attempting Local AI Analysis... ({attempt + 1}/{max_local_retries})")# response_raw = run_local_inference(report, base64_images)# if 'message' not in response_raw or 'content' not in response_raw['message']:# raise ValueError("Empty response structure from local AI")# ai_content = validate_ai_output(json.loads(response_raw['message']['content']))# response = { # type: ignore# "status": "success",# "data": ai_content,# "meta": {# "model": MODEL_NAME,# 'processing_time_sec': (response_raw.get("total_duration", 0)) / 1e9,# "images_analyzed": len(base64_images),# "source": "local",# "attempts": attempt + 1# }# }# print("Local AI Success")# print(json.dumps(response, indent=2, ensure_ascii=True))# return response # type: ignore# except Exception as e:# print(f"Local AI Attempt {attempt + 1} failed: {str(e)}")# last_local_exception = e# time.sleep(1)# print(f"Local model failed. Falling back to Gemini models.")if not GEMINI_MODEL_LIST:return JSONResponse(status_code=500,content={"status": "error","message": "Local AI failed and no Gemini models are configured for fallback.","local_model_error": str(last_local_exception),})print(GEMINI_MODEL_LIST)for model_name in [model_name for model_name in GEMINI_MODEL_LIST for _ in range(3)]:try:start_time = time.time()ai_content = validate_ai_output(run_gemini_inference(report, image_bytes_list, model_name))end_time = time.time()response = { # type: ignore"status": "success","data": ai_content,"meta": {"model": model_name,'processing_time_sec': end_time - start_time,"images_analyzed": len(image_bytes_list),"source": "gemini_fallback"}}print(f"Gemini AI Fallback Success with model {model_name}")print(json.dumps(response, indent=2, ensure_ascii=True))return response # type: ignoreexcept Exception as e:print(f"Gemini AI Fallback with model {model_name} failed: {str(e)}")last_gemini_exception = econtinuereturn JSONResponse(status_code=500,content={"status": "error","message": "All AI models (Local and Gemini fallbacks) failed to process the request.","local_model_error": str(last_local_exception),"last_gemini_model_error": str(last_gemini_exception)})if __name__ == "__main__":with gr.Blocks() as demo:gr.Markdown("# LAPOR AI API Backend")gr.Markdown("This space hosts the API endpoints for analyzing citizen reports. ""The primary endpoint is `/api/analyze` which uses a local model with a Gemini fallback.")gr.Markdown(f"**Local Model:** `{MODEL_NAME}`")gr.Markdown(f"**Fallback Models (in order):** `{', '.join(GEMINI_MODEL_LIST)}`")app = gr.mount_gradio_app(app, demo, path="/") # type: ignore
5 unmodified lines67895 unmodified linesgradiospacespython-dotenvPillow5 unmodified lines6789105 unmodified linesgradiospacespython-dotenvPillowgoogle-generativeai
.env+5-2
model/Modelfile → ModelfileRenamed
app.py+269-135
requirements.txt+2-1