Spaces:
Running
Running
| import os | |
| from nc_py_api import Nextcloud | |
| import json | |
| from datetime import datetime | |
| import time | |
| import threading | |
| import leaderboard | |
| ARENA_NAME = "# ๐ The GPU-Poor LLM Gladiator Arena ๐ v25.10" | |
| MAX_BATTLES_LIMIT = 150 | |
| # Ollama API configuration | |
| API_URL = os.environ.get("API_URL") | |
| API_KEY = os.environ.get("API_KEY") | |
| HEADERS = { | |
| "Content-Type": "application/json", | |
| "Authorization": f"Bearer {API_KEY}" | |
| } | |
| # API request settings | |
| API_TIMEOUT = 120 # Timeout in seconds | |
| MAX_TOKENS = 2048 # Max tokens for model response | |
| NEXTCLOUD_URL = os.environ.get("NEXTCLOUD_URL") | |
| NEXTCLOUD_USERNAME = os.environ.get("NEXTCLOUD_USERNAME") | |
| NEXTCLOUD_PASSWORD = os.environ.get("NEXTCLOUD_PASSWORD") | |
| NEXTCLOUD_LEADERBOARD_PATH = os.environ.get("NEXTCLOUD_LEADERBOARD_PATH") | |
| NEXTCLOUD_BACKUP_FOLDER = os.environ.get("NEXTCLOUD_BACKUP_FOLDER", "/gpu_poor_leaderboard_backups") | |
| NEXTCLOUD_SUGGESTIONS_PATH = os.environ.get("NEXTCLOUD_SUGGESTIONS_PATH", "/gpu_poor_model_suggestions.json") | |
| NEXTCLOUD_MODELS_PATH = os.environ.get("NEXTCLOUD_MODELS_PATH", "/gpu_poor_approved_models.json") | |
| # Nextcloud client singleton | |
| _nextcloud_client = None | |
| _nextcloud_lock = threading.Lock() | |
| def get_nextcloud_client(): | |
| global _nextcloud_client | |
| with _nextcloud_lock: | |
| if _nextcloud_client is None: | |
| _nextcloud_client = Nextcloud( | |
| nextcloud_url=NEXTCLOUD_URL, | |
| nc_auth_user=NEXTCLOUD_USERNAME, | |
| nc_auth_pass=NEXTCLOUD_PASSWORD | |
| ) | |
| return _nextcloud_client | |
| def load_approved_models(): | |
| """Load approved models from Nextcloud, fallback to local list if needed.""" | |
| try: | |
| nc = Nextcloud( | |
| nextcloud_url=NEXTCLOUD_URL, | |
| nc_auth_user=NEXTCLOUD_USERNAME, | |
| nc_auth_pass=NEXTCLOUD_PASSWORD | |
| ) | |
| # Try to load from Nextcloud | |
| remote_data = nc.files.download(NEXTCLOUD_MODELS_PATH) | |
| if remote_data: | |
| models_data = json.loads(remote_data.decode('utf-8')) | |
| return models_data['approved_models'] | |
| except Exception as e: | |
| print(f"Could not load models from Nextcloud: {e}") | |
| # Fallback to default models if Nextcloud fails | |
| return FALLBACK_MODELS | |
| # Add these constants | |
| MODEL_REFRESH_INTERVAL = 3600 # Check every 1 hour | |
| _last_model_check = 0 # Track last check time | |
| def get_approved_models(): | |
| """Get the current list of approved models with periodic refresh.""" | |
| global _last_model_check | |
| current_time = time.time() | |
| # Check if we need to refresh (if it's been more than MODEL_REFRESH_INTERVAL seconds) | |
| if not hasattr(get_approved_models, '_models') or \ | |
| (current_time - _last_model_check) > MODEL_REFRESH_INTERVAL: | |
| get_approved_models._models = load_approved_models() | |
| _last_model_check = current_time | |
| return get_approved_models._models | |
| def refresh_approved_models(): | |
| """Force refresh of the approved models list.""" | |
| if hasattr(get_approved_models, '_models'): | |
| delattr(get_approved_models, '_models') | |
| return get_approved_models() | |
| # Keep FALLBACK_MODELS as a safety net | |
| FALLBACK_MODELS = [ | |
| ("hf.co/unsloth/Qwen3-4B-Instruct-2507-GGUF:Q8_K_XL", "Qwen 3 Instruct 2507 Unsloth (4B, 8-bit)") | |
| ] | |
| # Example prompts | |
| example_prompts = [ | |
| "Explain how the internet works to someone from the 1800s.", | |
| "Design a new sport that combines elements of chess and basketball.", | |
| "Explain the idea behind Bitcoin using only food analogies.", | |
| "Write a dialogue between Socrates and a modern AI researcher about the nature of intelligence.", | |
| "Describe a color to someone who has been blind since birth.", | |
| "Compose a short speech convincing aliens not to destroy Earth.", | |
| "Explain the concept of infinity using a metaphor that doesn't involve numbers or math.", | |
| "Write a job description for a time traveler's assistant.", | |
| "If an AI and a human exchange messages 100 years apart, what does that mean for their relationship and understanding of time?", | |
| "How would you explain the concept of nostalgia to an AI that experiences all moments simultaneously?", | |
| "Create a thought experiment about an AI that can only communicate across decades - how would that shape its perspective?", | |
| "If AI experiences time non-linearly while humans experience it linearly, what philosophical questions does this raise?", | |
| "Imagine teaching the emotional weight of waiting to an AI that has no concept of anticipation - how would you approach it?", | |
| "Create a new philosophical thought experiment that challenges our understanding of reality.", | |
| "Describe how you would explain the concept of death to an immortal being.", | |
| "Invent a new emotion and describe how it feels, when it occurs, and its evolutionary purpose.", | |
| "Write a conversation between your future self and your past self, discussing the most important life lessons.", | |
| "Describe a day in the life of a sentient cloud.", | |
| "Create a new system of government based on the behavior of honeybees.", | |
| "Explain quantum entanglement using only elements from a typical kitchen.", | |
| "Design a universal language that could be understood by all species on Earth.", | |
| "Write a creation myth for the Internet age.", | |
| "Describe how you would teach empathy to an artificial intelligence.", | |
| "Invent a new primary color and explain its impact on the world.", | |
| "Compose a poem that can be read forwards and backwards, with different meanings in each direction.", | |
| "What are the main causes of climate change?", | |
| "Describe the process of photosynthesis in simple terms.", | |
| "Explain the concept of supply and demand in economics.", | |
| "What are the key differences between democracy and autocracy?", | |
| "How does the human immune system work?", | |
| "Summarize the plot of Romeo and Juliet in three sentences.", | |
| "What are the main features of the solar system?", | |
| "Explain the theory of evolution by natural selection.", | |
| "What are the primary functions of the United Nations?", | |
| "Describe the water cycle and its importance to life on Earth.", | |
| "Explain the biggest differences between Keynesian and Austrian economics.", | |
| "What are the main principles of the scientific method?", | |
| "Describe a world where humans communicate solely through music.", | |
| "Explain the concept of blockchain to a medieval blacksmith.", | |
| "Design a sustainable city that could exist on Mars.", | |
| "Write a short story where the protagonist is a sentient algorithm.", | |
| "Describe how you would reorganize the education system to prepare students for the 22nd century.", | |
| "Invent a new form of renewable energy and explain how it works.", | |
| "Create a recipe for a dish that represents world peace.", | |
| "Explain the importance of biodiversity using only references to a typical household.", | |
| "Design a new form of transportation that doesn't rely on wheels or engines.", | |
| "Write a letter from Earth to an alien civilization, introducing our planet and species.", | |
| "Describe how you would govern a society where everyone can read each other's thoughts.", | |
| "Explain the concept of time to a being that exists outside of it.", | |
| "Create a new theory of consciousness that incorporates both biological and artificial intelligence.", | |
| "Design a universal currency that could be used across different planets and species.", | |
| "Describe how you would solve overpopulation if teleportation was possible.", | |
| "Write a manifesto for a political party focused on preparing humanity for first contact with aliens.", | |
| "Explain how you would create a sustainable economy on a generation ship traveling to another solar system.", | |
| "Compose a lullaby for a baby robot.", | |
| "Describe the taste of water to a being that has never experienced liquid.", | |
| "Create a new art form that combines sculpture and interpretive dance.", | |
| "Explain the concept of democracy to a hive-mind alien species.", | |
| "Design a universal translator for animal languages.", | |
| "Write a creation myth for artificial intelligence.", | |
| "If you could ask an LLM one question to evaluate its capabilities. What is the question, and why would you ask it?", | |
| "Describe how you would teach the concept of love to a purely logical being.", | |
| "Invent a new sense beyond the traditional five and explain how it would work.", | |
| "Compose a speech for the first human colony on Mars, 100 years after settlement.", | |
| "Explain the concept of money to a society that has never used currency.", | |
| "Design a method of communication that works across parallel universes.", | |
| "Write a short story from the perspective of a photon traveling from the sun to Earth.", | |
| "Describe how you would organize a global government if suddenly all national borders disappeared.", | |
| "Invent a new philosophy based on the behavior of quantum particles.", | |
| "Create a new calendar system for a planet with three moons and two suns.", | |
| "Explain the concept of music to a species that communicates through bioluminescence.", | |
| "Design a legal system for a society of shapeshifters.", | |
| "Write a creation myth for the internet of things.", | |
| "Describe how you would teach ethics to an artificial general intelligence.", | |
| "Invent a new form of mathematics based on emotions instead of numbers.", | |
| "Compose a universal declaration of sentient rights that applies to all forms of consciousness.", | |
| ] | |
| model_nicknames = [ | |
| "๐ค Robo Responder", "๐งโโ๏ธ Wizard of Words", "๐ฆ Unicorn Utterance", | |
| "๐ง Brain Babbler", "๐ญ Prose Performer", "๐ Stellar Scribe", | |
| "๐ฎ Crystal Ball Chatter", "๐ฆ Wise Wordsmith", "๐ Rocket Replier", | |
| "๐จ Artful Answerer", "๐ Rainbow Rhetorician", "๐ Dragon Dialoguer", | |
| "๐ฆ Ice Cream Ideator", "๐ป Sunflower Speechifier", "๐ฉ Top Hat Thinker", | |
| "๐ Volcano Vocabularian", "๐ Wave of Wisdom", "๐ Mushroom Muser", | |
| "๐ฆ Butterfly Bard", "๐ Cosmic Conversationalist", | |
| "๐ต Melody Maestro", "๐ด Palm Tree Philosopher", "๐ฌ Lab Coat Linguist", | |
| "๐ Lunar Lyricist", "๐ Pizza Poet", "๐ฟ Herbal Haiku-ist", | |
| "๐ช Circus Sage", "๐ฐ Castle Chronicler", "๐บ Floral Phraseologist", | |
| "๐งฉ Puzzle Master Pontificator", "๐ญ Mask of Many Voices", | |
| "๐ณ Whispering Willow", "๐ง Gadget Guru Gabber", "๐งฌ Gene Genie Jawer", | |
| "๐งธ Teddy Bear Theorist", "๐จ Canvas Conversationalist", | |
| "๐งช Beaker Babbler", "๐ Prism Proclaimer", "๐งต Thread Theorist", | |
| "๐ง Ice Cube Ideator", "๐ก Ferris Wheel Philosopher", | |
| "๐ถ๏ธ Spicy Syntax Spinner", "๐งโโ๏ธ Mermaid Muse", "๐โโ๏ธ Surf Sage", | |
| "๐งโโ๏ธ Zen Zephyr", "๐ข Rollercoaster Raconteur", "๐งโโ๏ธ Fairy Tale Fabricator", | |
| "๐ญ Hot Dog Hypothesizer", "๐งโโ๏ธ Cliff Hanger Chronicler", "๐น Arrow Arguer", | |
| "๐งถ Yarn Yarner", "๐ Carousel Cogitator", "๐งฒ Magnet Metaphorist", | |
| "๐ฆ Parrot Paradoxer", "๐ฎ Taco Theorist", "๐งจ Firecracker Philosopher", | |
| "๐ณ Bowling Bard", "๐ง Cheese Chatterer", "๐ฆ Peacock Ponderer" | |
| ] | |
| def start_model_refresh_thread(): | |
| """Start a background thread to periodically refresh the models list.""" | |
| def refresh_models_periodically(): | |
| while True: | |
| time.sleep(MODEL_REFRESH_INTERVAL) | |
| try: | |
| refresh_approved_models() | |
| print(f"Models list refreshed at {datetime.now().strftime('%Y-%m-%d %H:%M:%S')}") | |
| except Exception as e: | |
| print(f"Error refreshing models list: {e}") | |
| refresh_thread = threading.Thread(target=refresh_models_periodically, daemon=True) | |
| refresh_thread.start() | |