builder / constants.py
mgbam's picture
Update constants.py
16552a3 verified
raw
history blame
3.18 kB
import os
import re
from http import HTTPStatus
from typing import Dict, List, Optional, Tuple
import base64
import mimetypes
import PyPDF2
import docx
import cv2
import numpy as np
from PIL import Image
import pytesseract
import requests
from urllib.parse import urlparse, urljoin
from bs4 import BeautifulSoup
import html2text
import json
import time
import webbrowser
import urllib.parse
import gradio as gr
# Load API keys from environment
HF_TOKEN = os.getenv("HF_TOKEN")
if not HF_TOKEN:
raise RuntimeError("HF_TOKEN environment variable is not set. Please set it to your Hugging Face API token.")
OPENAI_API_KEY = os.getenv("OPENAI_API_KEY")
if not OPENAI_API_KEY:
print("Warning: OPENAI_API_KEY not set; OpenAI provider will be unavailable.")
GEMINI_API_KEY = os.getenv("GEMINI_API_KEY")
if not GEMINI_API_KEY:
print("Warning: GEMINI_API_KEY not set; Gemini provider will be unavailable.")
# Gradio supported languages for syntax highlighting
GRADIO_SUPPORTED_LANGUAGES = [
"python", "c", "cpp", "markdown", "latex", "json", "html", "css", "javascript",
"jinja2", "typescript", "yaml", "dockerfile", "shell", "r", "sql", "sql-msSQL",
"sql-mySQL", "sql-mariaDB", "sql-sqlite", "sql-cassandra", "sql-plSQL", "sql-hive",
"sql-pgSQL", "sql-gql", "sql-gpSQL", "sql-sparkSQL", "sql-esper", None
]
def get_gradio_language(language):
return language if language in GRADIO_SUPPORTED_LANGUAGES else None
# Search/Replace Constants
SEARCH_START = "<<<<<<< SEARCH"
DIVIDER = "======="
REPLACE_END = ">>>>>>> REPLACE"
# System prompts
HTML_SYSTEM_PROMPT = """ONLY USE HTML, CSS AND JAVASCRIPT. ... Always output only the HTML code inside a ```html ... ``` code block."""
TRANSFORMERS_JS_SYSTEM_PROMPT = """You are an expert web developer creating a transformers.js application. ... Always output only the three code blocks as shown above, and do not include any explanations or extra text."""
# Available HF models for code generation
AVAILABLE_MODELS = [
{"name": "Moonshot Kimi-K2", "id": "moonshotai/Kimi-K2-Instruct", "description": "Moonshot AI Kimi-K2-Instruct model"},
{"name": "DeepSeek V3", "id": "deepseek-ai/DeepSeek-V3-0324", "description": "DeepSeek V3 model"},
{"name": "DeepSeek R1", "id": "deepseek-ai/DeepSeek-R1-0528", "description": "DeepSeek R1 model"},
{"name": "ERNIE-4.5-VL", "id": "baidu/ERNIE-4.5-VL-424B-A47B-Base-PT", "description": "ERNIE-4.5-VL model"},
{"name": "MiniMax M1", "id": "MiniMaxAI/MiniMax-M1-80k", "description": "MiniMax M1 model"},
{"name": "Qwen3-235B-A22B", "id": "Qwen/Qwen3-235B-A22B", "description": "Qwen3-235B-A22B model"},
{"name": "SmolLM3-3B", "id": "HuggingFaceTB/SmolLM3-3B", "description": "SmolLM3-3B model"},
{"name": "GLM-4.1V-9B-Thinking", "id": "THUDM/GLM-4.1V-9B-Thinking", "description": "GLM-4.1V-9B-Thinking model"},
{"name": "OpenAI GPT-4", "id": "openai/gpt-4", "description": "OpenAI GPT-4 model"},
{"name": "Gemini Pro", "id": "gemini/pro", "description": "Google Gemini Pro model"},
{"name": "Fireworks AI", "id": "fireworks-ai/fireworks-v1", "description": "Fireworks AI model"},
]
# Quick‑start demo list
DEMO_LIST = [ ... ]