update
Browse filesThis view is limited to 50 files because it contains too many changes. See raw diff
Files changed (50)
- .gitattributesDeleted-35
- .gitignore+20-101
- .pre-commit-config.yamlDeleted-32
- .python-versionDeleted-1
- .vscode/extensions.jsonDeleted-8
- .vscode/settings.jsonDeleted-16
- README.md+80-1
- app.cssAdded+59
- app.py+288-50
- app_allenai.pyDeleted-67
- app_cerebras.pyDeleted-19
- app_claude.pyDeleted-21
- app_cohere.pyDeleted-21
- app_compare.pyDeleted-210
- app_crew.pyDeleted-8
- app_deepseek.pyDeleted-23
- app_experimental.pyDeleted-300
- app_fal.pyDeleted-16
- app_fireworks.pyDeleted-19
- app_gemini.pyDeleted-22
- app_gemini_camera.pyDeleted-23
- app_gemini_coder.pyDeleted-23
- app_gemini_voice.pyDeleted-23
- app_groq.pyDeleted-21
- app_groq_coder.pyDeleted-23
- app_hf.pyDeleted-17
- app_huggingface.pyDeleted-22
- app_hyperbolic.pyDeleted-19
- app_hyperbolic_coder.pyDeleted-20
- app_langchain.pyDeleted-23
- app_lumaai.pyDeleted-7
- app_marco_o1.pyDeleted-12
- app_meta.pyDeleted-6
- app_mindsearch.pyDeleted-12
- app_minimax.pyDeleted-22
- app_minimax_coder.pyDeleted-23
- app_mistral.pyDeleted-23
- app_moondream.pyDeleted-13
- app_nvidia.pyDeleted-22
- app_nvidia_coder.pyDeleted-23
- app_omini.pyDeleted-10
- app_openai.pyDeleted-21
- app_openai_coder.pyDeleted-22
- app_openai_voice.pyDeleted-23
- app_openrouter.pyDeleted-22
- app_paligemma.pyDeleted-78
- app_perplexity.pyDeleted-23
- app_playai.pyDeleted-10
- app_qwen.pyDeleted-19
- app_qwen_coder.pyDeleted-20
1234567891011121314151617181920212223242526272829303132333435*.7z filter=lfs diff=lfs merge=lfs -text*.arrow filter=lfs diff=lfs merge=lfs -text*.bin filter=lfs diff=lfs merge=lfs -text*.bz2 filter=lfs diff=lfs merge=lfs -text*.ckpt filter=lfs diff=lfs merge=lfs -text*.ftz filter=lfs diff=lfs merge=lfs -text*.gz filter=lfs diff=lfs merge=lfs -text*.h5 filter=lfs diff=lfs merge=lfs -text*.joblib filter=lfs diff=lfs merge=lfs -text*.lfs.* filter=lfs diff=lfs merge=lfs -text*.mlmodel filter=lfs diff=lfs merge=lfs -text*.model filter=lfs diff=lfs merge=lfs -text*.msgpack filter=lfs diff=lfs merge=lfs -text*.npy filter=lfs diff=lfs merge=lfs -text*.npz filter=lfs diff=lfs merge=lfs -text*.onnx filter=lfs diff=lfs merge=lfs -text*.ot filter=lfs diff=lfs merge=lfs -text*.parquet filter=lfs diff=lfs merge=lfs -text*.pb filter=lfs diff=lfs merge=lfs -text*.pickle filter=lfs diff=lfs merge=lfs -text*.pkl filter=lfs diff=lfs merge=lfs -text*.pt filter=lfs diff=lfs merge=lfs -text*.pth filter=lfs diff=lfs merge=lfs -text*.rar filter=lfs diff=lfs merge=lfs -text*.safetensors filter=lfs diff=lfs merge=lfs -textsaved_model/**/* filter=lfs diff=lfs merge=lfs -text*.tar.* filter=lfs diff=lfs merge=lfs -text*.tar filter=lfs diff=lfs merge=lfs -text*.tflite filter=lfs diff=lfs merge=lfs -text*.tgz filter=lfs diff=lfs merge=lfs -text*.wasm filter=lfs diff=lfs merge=lfs -text*.xz filter=lfs diff=lfs merge=lfs -text*.zip filter=lfs diff=lfs merge=lfs -text*.zst filter=lfs diff=lfs merge=lfs -text*tfevents* filter=lfs diff=lfs merge=lfs -text1212315 unmodified lines1920212425222324252627282930313233323334353611 unmodified lines48495051515254555657585960616263646566676869707172737475767778535455568384858657888990589192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401415960616214663646566151152676869707172737415415575767778791571581591601611628081.gradio/
# Byte-compiled / optimized / DLL files__pycache__/*.py[cod]15 unmodified linesparts/sdist/var/wheels/share/python-wheels/*.egg-info/.installed.cfg*.eggMANIFEST
# Virtual environmentsvenv/env/ENV/.venv/
# PyInstaller# Usually these files are written by a python script from a template# before PyInstaller builds the exe, so as to inject date/other infos into it.*.manifest*.spec
11 unmodified linesnosetests.xmlcoverage.xml*.cover*.py,cover.hypothesis/.pytest_cache/cover/
# Translations*.mo*.pot
# Django stuff:*.loglocal_settings.pydb.sqlite3db.sqlite3-journal
# Flask stuff:instance/.webassets-cache
# Scrapy stuff:.scrapy
# Sphinx documentationdocs/_build/
# PyBuilder.pybuilder/target/
# Jupyter Notebook.ipynb_checkpoints
# IPythonprofile_default/ipython_config.py
# pyenv# For a library or package, you might want to ignore these files since the code is# intended to run in multiple environments; otherwise, check them in:# .python-version.python-version
# pipenv# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.# However, in case of collaboration, if having platform-specific dependencies or dependencies# having no cross-platform support, pipenv may install dependencies that don't work, or not# install all needed dependencies.#Pipfile.lock
# poetry# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.# This is especially recommended for binary packages to ensure reproducibility, and is more# commonly ignored for libraries.# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control#poetry.lock
# pdm# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.#pdm.lock# pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it# in version control.# https://pdm.fming.dev/#use-with-ide.pdm.toml
# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm__pypackages__/
# Celery stuffcelerybeat-schedulecelerybeat.pid
# SageMath parsed files*.sage.py
# Environments.env.venvenv/venv/ENV/env.bak/venv.bak/
# Spyder project settings.spyderproject.spyproject
# Rope project settings.ropeproject
# mkdocs documentation/site
# mypy.mypy_cache/.dmypy.jsondmypy.json
# Pyre type checker.pyre/
# pytype static type analyzer.pytype/# Gradio cachelog/logs/
# System files.DS_StoreThumbs.db
# Cython debug symbolscython_debug/# Lock filesuv.lockpoetry.lockPipfile.lock
# PyCharm# JetBrains specific template is maintained in a separate JetBrains.gitignore that can# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore# and can be added to the global gitignore or merged into this file. For a more nuclear# option (not recommended) you can uncomment the following to ignore the entire idea folder.#.idea/# VSCode.vscode/ 1234567891011121314151617181920212223242526272829303132repos: - repo: https://github.com/pre-commit/pre-commit-hooks rev: v5.0.0 hooks: - id: check-executables-have-shebangs - id: check-json - id: check-merge-conflict - id: check-shebang-scripts-are-executable - id: check-toml - id: check-yaml - id: end-of-file-fixer - id: mixed-line-ending args: ["--fix=lf"] - id: requirements-txt-fixer - id: trailing-whitespace - repo: https://github.com/astral-sh/ruff-pre-commit rev: v0.8.6 hooks: - id: ruff args: ["--fix"] - repo: https://github.com/pre-commit/mirrors-mypy rev: v1.14.1 hooks: - id: mypy args: ["--ignore-missing-imports"] additional_dependencies: [ "types-python-slugify", "types-requests", "types-PyYAML", "types-pytz", ]13.1012345678{ "recommendations": [ "ms-python.python", "charliermarsh.ruff", "streetsidesoftware.code-spell-checker", "tamasfe.even-better-toml" ]}12345678910111213141516{ "editor.formatOnSave": true, "files.insertFinalNewline": false, "[python]": { "editor.defaultFormatter": "charliermarsh.ruff", "editor.formatOnType": true, "editor.codeActionsOnSave": { "source.fixAll.ruff": "explicit" } }, "[jupyter]": { "files.insertFinalNewline": false }, "notebook.output.scrolling": true, "notebook.formatOnSave.enabled": true}9 unmodified lines1011121313141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929 unmodified linesdisable_embedding: true---
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-referenceCheck out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
# Anycoder - AI Code Generation with Hugging Face Inference
An ultra-clean AI-powered code generation application using Hugging Face inference providers. Minimal files for maximum simplicity.
## Features
- **Hugging Face Models**: Uses DeepSeek-V3-0324 via Novita provider- **Modern UI**: Built with Gradio and ModelScope Studio components- **Code Generation**: Generates working code based on user requirements- **Live Preview**: Renders generated HTML code in real-time- **History Management**: Keeps track of conversation history- **Streaming**: Real-time code generation with streaming responses
## Project Structure
```anycoder/├── app.py # Main application (everything included)├── app.css # Basic styling├── pyproject.toml # Dependencies└── README.md # This file```
## Setup
1. Set your Hugging Face API token: ```bash export HF_TOKEN="your_huggingface_token_here" ```
2. Install dependencies: ```bash uv sync ```
3. Run the application: ```bash uv run python app.py ```
## Usage
1. Enter your application requirements in the text area2. Click "send" to generate code3. View the generated code in the code drawer4. See the live preview in the sandbox area5. Use example cards for quick prompts
## Code Example
```pythonimport osfrom huggingface_hub import InferenceClient
client = InferenceClient( provider="novita", api_key=os.environ["HF_TOKEN"], bill_to="huggingface")
completion = client.chat.completions.create( model="deepseek-ai/DeepSeek-V3-0324", messages=[ { "role": "user", "content": "Create a simple todo app" } ],)```
## Architecture
The application uses:- **Gradio**: For the web interface- **Hugging Face Hub**: For model inference- **ModelScope Studio**: For UI components- **Streaming**: For real-time code generation1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859/* Basic styling for the coder application */
.left_header { text-align: center; margin-bottom: 20px;}
.left_header h1 { margin-top: 10px; color: #333;}
.right_panel { background: #f5f5f5; border-radius: 8px; padding: 20px; height: 100%;}
.render_header { display: flex; gap: 8px; margin-bottom: 15px;}
.header_btn { width: 12px; height: 12px; border-radius: 50%; background: #ff5f56;}
.header_btn:nth-child(2) { background: #ffbd2e;}
.header_btn:nth-child(3) { background: #27ca3f;}
.right_content { display: flex; align-items: center; justify-content: center; height: 800px;}
.html_content { width: 100%; height: 920px; border: none; border-radius: 8px; background: white;}
.history_chatbot { max-height: 960px; overflow-y: auto;}12341234566789101112131415161771920212223242526272829303132333435363738394041424344454647484950518910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029154292from app_huggingface import demo as demo_huggingfacefrom app_gemini_coder import demo as demo_geminifrom utils import get_appimport gradio as grimport osimport refrom http import HTTPStatusfrom typing import Dict, List, Optional, Tupleimport base64
# Create mapping of providers to their code snippetsPROVIDER_SNIPPETS = { "Hugging Face": """import gradio as grimport ai_gradiogr.load( name='huggingface:deepseek-ai/DeepSeek-R1', src=ai_gradio.registry, coder=True, provider="together").launch()""", "Gemini Coder": """import gradio as grimport ai_gradiogr.load( name='gemini:gemini-2.5-pro-exp-03-25', src=ai_gradio.registry, coder=True, provider="together").launch() """,}# Create mapping of providers to their demosPROVIDERS = { "Hugging Face": demo_huggingface, "Gemini Coder": demo_gemini,}
# Modified get_app implementationdemo = gr.Blocks()with demo:
provider_dropdown = gr.Dropdown(choices=list(PROVIDERS.keys()), value="Hugging Face", label="Select code snippet") code_display = gr.Code(label="Provider Code Snippet", language="python", value=PROVIDER_SNIPPETS["Hugging Face"])
def update_code(provider): return PROVIDER_SNIPPETS.get(provider, "Code snippet not available")
provider_dropdown.change(fn=update_code, inputs=[provider_dropdown], outputs=[code_display])
selected_demo = get_app( models=list(PROVIDERS.keys()), default_model="Hugging Face", src=PROVIDERS, dropdown_label="Select Provider", )from huggingface_hub import InferenceClient
import modelscope_studio.components.base as msimport modelscope_studio.components.legacy as legacyimport modelscope_studio.components.antd as antd
# ConfigurationSystemPrompt = """You are a helpful coding assistant. You help users create applications by generating code based on their requirements. When asked to create an application, you should:1. Understand the user's requirements2. Generate clean, working code3. Provide HTML output when appropriate for web applications4. Include necessary comments and documentation5. Ensure the code is functional and follows best practices
Always respond with code that can be executed or rendered directly.
Always output only the HTML code inside a ```html ... ``` code block, and do not include any explanations or extra text."""
DEMO_LIST = [ { "title": "Todo App", "description": "Create a simple todo application with add, delete, and mark as complete functionality" }, { "title": "Calculator", "description": "Build a basic calculator with addition, subtraction, multiplication, and division" }, { "title": "Weather Dashboard", "description": "Create a weather dashboard that displays current weather information" }, { "title": "Chat Interface", "description": "Build a chat interface with message history and user input" }, { "title": "E-commerce Product Card", "description": "Create a product card component for an e-commerce website" }, { "title": "Login Form", "description": "Build a responsive login form with validation" }, { "title": "Dashboard Layout", "description": "Create a dashboard layout with sidebar navigation and main content area" }, { "title": "Data Table", "description": "Build a data table with sorting and filtering capabilities" }]
# HF Inference ClientYOUR_API_TOKEN = os.getenv('HF_TOKEN')client = InferenceClient( provider="novita", api_key=YOUR_API_TOKEN, bill_to="huggingface")
History = List[Tuple[str, str]]Messages = List[Dict[str, str]]
def history_to_messages(history: History, system: str) -> Messages: messages = [{'role': 'system', 'content': system}] for h in history: messages.append({'role': 'user', 'content': h[0]}) messages.append({'role': 'assistant', 'content': h[1]}) return messages
def messages_to_history(messages: Messages) -> Tuple[str, History]: assert messages[0]['role'] == 'system' history = [] for q, r in zip(messages[1::2], messages[2::2]): history.append([q['content'], r['content']]) return history
def remove_code_block(text): # Try to match code blocks with language markers patterns = [ r'```(?:html|HTML)\n([\s\S]+?)\n```', # Match ```html or ```HTML r'```\n([\s\S]+?)\n```', # Match code blocks without language markers r'```([\s\S]+?)```' # Match code blocks without line breaks ] for pattern in patterns: match = re.search(pattern, text, re.DOTALL) if match: extracted = match.group(1).strip() print("Successfully extracted code block:", extracted) return extracted # If no code block is found, check if the entire text is HTML if text.strip().startswith('<!DOCTYPE html>') or text.strip().startswith('<html'): print("Text appears to be raw HTML, using as is") return text.strip() print("No code block found in text:", text) return text.strip()
def history_render(history: History): return gr.update(open=True), history
def clear_history(): return []
def send_to_sandbox(code): # Add a wrapper to inject necessary permissions and ensure full HTML wrapped_code = f""" <!DOCTYPE html> <html> <head> <meta charset=\"UTF-8\"> <meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\"> <script> // Safe localStorage polyfill const safeStorage = {{ _data: {{}}, getItem: function(key) {{ return this._data[key] || null; }}, setItem: function(key, value) {{ this._data[key] = value; }}, removeItem: function(key) {{ delete this._data[key]; }}, clear: function() {{ this._data = {{}}; }} }}; Object.defineProperty(window, 'localStorage', {{ value: safeStorage, writable: false }}); window.onerror = function(message, source, lineno, colno, error) {{ console.error('Error:', message); }}; </script> </head> <body> {code} </body> </html> """ encoded_html = base64.b64encode(wrapped_code.encode('utf-8')).decode('utf-8') data_uri = f"data:text/html;charset=utf-8;base64,{encoded_html}" iframe = f'<iframe src="{data_uri}" width="100%" height="920px" sandbox="allow-scripts allow-same-origin allow-forms allow-popups allow-modals allow-presentation" allow="display-capture"></iframe>' print("Generated iframe:", iframe) return iframe
def demo_card_click(e: gr.EventData): try: # Try to get the index from the event data if hasattr(e, '_data') and e._data and 'component' in e._data: index = e._data['component'].get('index', 0) else: # Fallback to first item if we can't get the index index = 0 return DEMO_LIST[index]['description'] except (KeyError, IndexError, AttributeError): # Return the first demo description as fallback return DEMO_LIST[0]['description']
# Main applicationwith gr.Blocks(css_paths="app.css") as demo: history = gr.State([]) setting = gr.State({ "system": SystemPrompt, })
with ms.Application() as app: with antd.ConfigProvider(): with antd.Row(gutter=[32, 12]) as layout: with antd.Col(span=24, md=8): with antd.Flex(vertical=True, gap="middle", wrap=True): header = gr.HTML(""" <div class="left_header"> <img src="//img.alicdn.com/imgextra/i2/O1CN01KDhOma1DUo8oa7OIU_!!6000000000220-1-tps-240-240.gif" width="200px" /> <h1>HF Coder</h1> </div> """) input = antd.InputTextarea( size="large", allow_clear=True, placeholder="Please enter what kind of application you want") btn = antd.Button("send", type="primary", size="large") clear_btn = antd.Button("clear history", type="default", size="large")
antd.Divider("examples") with antd.Flex(gap="small", wrap=True): with ms.Each(DEMO_LIST): with antd.Card(hoverable=True, as_item="card") as demoCard: antd.CardMeta() demoCard.click(demo_card_click, outputs=[input])
antd.Divider("setting")
with antd.Flex(gap="small", wrap=True): settingPromptBtn = antd.Button( "⚙️ set system Prompt", type="default") codeBtn = antd.Button("🧑💻 view code", type="default") historyBtn = antd.Button("📜 history", type="default")
with antd.Modal(open=False, title="set system Prompt", width="800px") as system_prompt_modal: systemPromptInput = antd.InputTextarea( SystemPrompt, auto_size=True)
settingPromptBtn.click(lambda: gr.update( open=True), inputs=[], outputs=[system_prompt_modal]) system_prompt_modal.ok(lambda input: ({"system": input}, gr.update( open=False)), inputs=[systemPromptInput], outputs=[setting, system_prompt_modal]) system_prompt_modal.cancel(lambda: gr.update( open=False), outputs=[system_prompt_modal])
with antd.Drawer(open=False, title="code", placement="left", width="750px") as code_drawer: code_output = legacy.Markdown()
codeBtn.click(lambda: gr.update(open=True), inputs=[], outputs=[code_drawer]) code_drawer.close(lambda: gr.update( open=False), inputs=[], outputs=[code_drawer])
with antd.Drawer(open=False, title="history", placement="left", width="900px") as history_drawer: history_output = legacy.Chatbot(show_label=False, flushing=False, height=960, elem_classes="history_chatbot")
historyBtn.click(history_render, inputs=[history], outputs=[history_drawer, history_output]) history_drawer.close(lambda: gr.update( open=False), inputs=[], outputs=[history_drawer])
with antd.Col(span=24, md=16): with ms.Div(elem_classes="right_panel"): gr.HTML('<div class="render_header"><span class="header_btn"></span><span class="header_btn"></span><span class="header_btn"></span></div>') # Move sandbox outside of tabs for always-on visibility sandbox = gr.HTML(elem_classes="html_content") with antd.Tabs(active_key="empty", render_tab_bar="() => null") as state_tab: with antd.Tabs.Item(key="empty"): empty = antd.Empty(description="empty input", elem_classes="right_content") with antd.Tabs.Item(key="loading"): loading = antd.Spin(True, tip="coding...", size="large", elem_classes="right_content")
def generation_code(query: Optional[str], _setting: Dict[str, str], _history: Optional[History]): if query is None: query = '' if _history is None: _history = [] messages = history_to_messages(_history, _setting['system']) messages.append({'role': 'user', 'content': query})
try: completion = client.chat.completions.create( model="deepseek-ai/DeepSeek-V3-0324", messages=messages, stream=True ) content = "" for chunk in completion: if chunk.choices[0].delta.content: content += chunk.choices[0].delta.content yield { code_output: content, state_tab: gr.update(active_key="loading"), code_drawer: gr.update(open=True), } # Final response _history = messages_to_history(messages + [{ 'role': 'assistant', 'content': content }]) yield { code_output: content, history: _history, sandbox: send_to_sandbox(remove_code_block(content)), state_tab: gr.update(active_key="render"), code_drawer: gr.update(open=False), } except Exception as e: error_message = f"Error: {str(e)}" yield { code_output: error_message, state_tab: gr.update(active_key="empty"), code_drawer: gr.update(open=True), }
btn.click(generation_code, inputs=[input, setting, history], outputs=[code_output, history, sandbox, state_tab, code_drawer]) clear_btn.click(clear_history, inputs=[], outputs=[history])
if __name__ == "__main__": demo.queue(api_open=False).launch(show_api=False) demo.queue(default_concurrency_limit=20).launch(ssr_mode=False)12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667import gradio as grfrom gradio_client import Client
MODELS = {"OLMo-2-1124-13B-Instruct": "akhaliq/olmo-anychat", "Llama-3.1-Tulu-3-8B": "akhaliq/allen-test"}
def create_chat_fn(client): def chat(message, history): response = client.predict( message=message, system_prompt="You are a helpful AI assistant.", temperature=0.7, max_new_tokens=1024, top_k=40, repetition_penalty=1.1, top_p=0.95, api_name="/chat", ) return response
return chat
def set_client_for_session(model_name, request: gr.Request): headers = {} if request and hasattr(request, "request") and hasattr(request.request, "headers"): x_ip_token = request.request.headers.get("x-ip-token") if x_ip_token: headers["X-IP-Token"] = x_ip_token
return Client(MODELS[model_name], headers=headers)
def safe_chat_fn(message, history, client): if client is None: return "Error: Client not initialized. Please refresh the page." return create_chat_fn(client)(message, history)
with gr.Blocks() as demo: client = gr.State()
model_dropdown = gr.Dropdown( choices=list(MODELS.keys()), value="OLMo-2-1124-13B-Instruct", label="Select Model", interactive=True )
chat_interface = gr.ChatInterface(fn=safe_chat_fn, additional_inputs=[client])
# Update client when model changes def update_model(model_name, request): return set_client_for_session(model_name, request)
model_dropdown.change( fn=update_model, inputs=[model_dropdown], outputs=[client], )
# Initialize client on page load demo.load( fn=set_client_for_session, inputs=gr.State("OLMo-2-1124-13B-Instruct"), outputs=client, )
if __name__ == "__main__": demo.launch()12345678910111213141516171819import os
import cerebras_gradio
from utils import get_app
demo = get_app( models=[ "llama3.1-8b", "llama3.1-70b", "llama3.1-405b", ], default_model="llama3.1-70b", src=cerebras_gradio.registry, accept_token=not os.getenv("CEREBRAS_API_KEY"),)
if __name__ == "__main__": demo.launch()123456789101112131415161718192021import os
import anthropic_gradio
from utils import get_app
demo = get_app( models=[ "claude-3-5-sonnet-20241022", "claude-3-5-haiku-20241022", "claude-3-opus-20240229", "claude-3-sonnet-20240229", "claude-3-haiku-20240307", ], default_model="claude-3-5-sonnet-20241022", src=anthropic_gradio.registry, accept_token=not os.getenv("ANTHROPIC_API_KEY"),)
if __name__ == "__main__": demo.launch()123456789101112131415161718192021import os
import cohere_gradio
from utils import get_app
demo = get_app( models=[ "command-r", "command-r-08-2024", "command-r-plus", "command-r-plus-08-2024", "command-r7b-12-2024", ], default_model="command-r7b-12-2024", src=cohere_gradio.registry, accept_token=not os.getenv("COHERE_API_KEY"),)
if __name__ == "__main__": demo.launch()123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210import os
import google.generativeai as genaiimport gradio as grimport openaifrom anthropic import Anthropicfrom openai import OpenAI # Add explicit OpenAI import
def get_all_models(): """Get all available models from the registries.""" return [ "SambaNova: Meta-Llama-3.2-1B-Instruct", "SambaNova: Meta-Llama-3.2-3B-Instruct", "SambaNova: Llama-3.2-11B-Vision-Instruct", "SambaNova: Llama-3.2-90B-Vision-Instruct", "SambaNova: Meta-Llama-3.1-8B-Instruct", "SambaNova: Meta-Llama-3.1-70B-Instruct", "SambaNova: Meta-Llama-3.1-405B-Instruct", "Hyperbolic: Qwen/Qwen2.5-Coder-32B-Instruct", "Hyperbolic: meta-llama/Llama-3.2-3B-Instruct", "Hyperbolic: meta-llama/Meta-Llama-3.1-8B-Instruct", "Hyperbolic: meta-llama/Meta-Llama-3.1-70B-Instruct", "Hyperbolic: meta-llama/Meta-Llama-3-70B-Instruct", "Hyperbolic: NousResearch/Hermes-3-Llama-3.1-70B", "Hyperbolic: Qwen/Qwen2.5-72B-Instruct", "Hyperbolic: deepseek-ai/DeepSeek-V2.5", "Hyperbolic: meta-llama/Meta-Llama-3.1-405B-Instruct", ]
def generate_discussion_prompt(original_question: str, previous_responses: list[str]) -> str: """Generate a prompt for models to discuss and build upon previous responses. """ prompt = f"""You are participating in a multi-AI discussion about this question: "{original_question}"
Previous responses from other AI models:{chr(10).join(f"- {response}" for response in previous_responses)}
Please provide your perspective while:1. Acknowledging key insights from previous responses2. Adding any missing important points3. Respectfully noting if you disagree with anything and explaining why4. Building towards a complete answer
Keep your response focused and concise (max 3-4 paragraphs).""" return prompt
def generate_consensus_prompt(original_question: str, discussion_history: list[str]) -> str: """Generate a prompt for final consensus building.""" return f"""Review this multi-AI discussion about: "{original_question}"
Discussion history:{chr(10).join(discussion_history)}
As a final synthesizer, please:1. Identify the key points where all models agreed2. Explain how any disagreements were resolved3. Present a clear, unified answer that represents our collective best understanding4. Note any remaining uncertainties or caveats
Keep the final consensus concise but complete."""
def chat_with_openai(model: str, messages: list[dict], api_key: str | None) -> str: import openai
client = openai.OpenAI(api_key=api_key) response = client.chat.completions.create(model=model, messages=messages) return response.choices[0].message.content
def chat_with_anthropic(messages: list[dict], api_key: str | None) -> str: """Chat with Anthropic's Claude model.""" client = Anthropic(api_key=api_key) response = client.messages.create(model="claude-3-sonnet-20240229", messages=messages, max_tokens=1024) return response.content[0].text
def chat_with_gemini(messages: list[dict], api_key: str | None) -> str: """Chat with Gemini Pro model.""" genai.configure(api_key=api_key) model = genai.GenerativeModel("gemini-pro")
# Convert messages to Gemini format gemini_messages = [] for msg in messages: role = "user" if msg["role"] == "user" else "model" gemini_messages.append({"role": role, "parts": [msg["content"]]})
response = model.generate_content([m["parts"][0] for m in gemini_messages]) return response.text
def chat_with_sambanova( messages: list[dict], api_key: str | None, model_name: str = "Llama-3.2-90B-Vision-Instruct") -> str: """Chat with SambaNova's models using their OpenAI-compatible API.""" client = openai.OpenAI( api_key=api_key, base_url="https://api.sambanova.ai/v1", )
response = client.chat.completions.create( model=model_name, messages=messages, temperature=0.1, top_p=0.1, # Use the specific model name passed in ) return response.choices[0].message.content
def chat_with_hyperbolic( messages: list[dict], api_key: str | None, model_name: str = "Qwen/Qwen2.5-Coder-32B-Instruct") -> str: """Chat with Hyperbolic's models using their OpenAI-compatible API.""" client = OpenAI(api_key=api_key, base_url="https://api.hyperbolic.xyz/v1")
# Add system message to the start of the messages list full_messages = [ {"role": "system", "content": "You are a helpful assistant. Be descriptive and clear."}, *messages, ]
response = client.chat.completions.create( model=model_name, # Use the specific model name passed in messages=full_messages, temperature=0.7, max_tokens=1024, ) return response.choices[0].message.content
def multi_model_consensus( question: str, selected_models: list[str], rounds: int = 3, progress: gr.Progress = gr.Progress()) -> list[tuple[str, str]]: if not selected_models: raise gr.Error("Please select at least one model to chat with.")
chat_history = [] progress(0, desc="Getting responses from all models...")
# Get responses from all models in parallel for i, model in enumerate(selected_models): provider, model_name = model.split(": ", 1) progress((i + 1) / len(selected_models), desc=f"Getting response from {model}...")
try: if provider == "Anthropic": api_key = os.getenv("ANTHROPIC_API_KEY") response = chat_with_anthropic(messages=[{"role": "user", "content": question}], api_key=api_key) elif provider == "SambaNova": api_key = os.getenv("SAMBANOVA_API_KEY") response = chat_with_sambanova( messages=[ {"role": "system", "content": "You are a helpful assistant"}, {"role": "user", "content": question}, ], api_key=api_key, model_name=model_name, ) elif provider == "Hyperbolic": api_key = os.getenv("HYPERBOLIC_API_KEY") response = chat_with_hyperbolic( messages=[{"role": "user", "content": question}], api_key=api_key, model_name=model_name, ) else: # Gemini api_key = os.getenv("GEMINI_API_KEY") response = chat_with_gemini(messages=[{"role": "user", "content": question}], api_key=api_key)
chat_history.append((model, response)) except Exception as e: chat_history.append((model, f"Error: {e!s}"))
progress(1.0, desc="Done!") return chat_history
with gr.Blocks() as demo: gr.Markdown("# Model Response Comparison") gr.Markdown("""Select multiple models to compare their responses""")
with gr.Row(): with gr.Column(): model_selector = gr.Dropdown( choices=get_all_models(), multiselect=True, label="Select Models", info="Choose models to compare", value=["SambaNova: Llama-3.2-90B-Vision-Instruct", "Hyperbolic: Qwen/Qwen2.5-Coder-32B-Instruct"], )
chatbot = gr.Chatbot(height=600, label="Model Responses") msg = gr.Textbox(label="Prompt", placeholder="Ask a question to compare model responses...")
def respond(message, selected_models): chat_history = multi_model_consensus(message, selected_models, rounds=1) return chat_history
msg.submit(respond, [msg, model_selector], [chatbot])
for fn in demo.fns.values(): fn.api_name = False
if __name__ == "__main__": demo.launch()12345678import ai_gradioimport gradio as gr
demo = gr.load( name="crewai:gpt-4-turbo", crew_type="article", # or 'support' src=ai_gradio.registry,)1234567891011121314151617181920212223import ai_gradio
from utils_ai_gradio import get_app
# Get the hyperbolic models but keep their full names for loadingDEEPSEEK_MODELS_FULL = [k for k in ai_gradio.registry.keys() if k.startswith("deepseek:")]
# Create display names without the prefixDEEPSEEK_MODELS_DISPLAY = [k.replace("deepseek:", "") for k in DEEPSEEK_MODELS_FULL]
# Create and launch the interface using get_app utilitydemo = get_app( models=DEEPSEEK_MODELS_FULL, # Use the full names with prefix default_model=DEEPSEEK_MODELS_FULL[-1], dropdown_label="Select DeepSeek Model", choices=DEEPSEEK_MODELS_DISPLAY, # Display names without prefix fill_height=True, coder=True,)
if __name__ == "__main__": demo.launch()123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300import osimport random
import google.generativeai as genaiimport gradio as grimport openaifrom anthropic import Anthropicfrom openai import OpenAI # Add explicit OpenAI import
def get_all_models(): """Get all available models from the registries.""" return [ "SambaNova: Meta-Llama-3.2-1B-Instruct", "SambaNova: Meta-Llama-3.2-3B-Instruct", "SambaNova: Llama-3.2-11B-Vision-Instruct", "SambaNova: Llama-3.2-90B-Vision-Instruct", "SambaNova: Meta-Llama-3.1-8B-Instruct", "SambaNova: Meta-Llama-3.1-70B-Instruct", "SambaNova: Meta-Llama-3.1-405B-Instruct", "Hyperbolic: Qwen/Qwen2.5-Coder-32B-Instruct", "Hyperbolic: meta-llama/Llama-3.2-3B-Instruct", "Hyperbolic: meta-llama/Meta-Llama-3.1-8B-Instruct", "Hyperbolic: meta-llama/Meta-Llama-3.1-70B-Instruct", "Hyperbolic: meta-llama/Meta-Llama-3-70B-Instruct", "Hyperbolic: NousResearch/Hermes-3-Llama-3.1-70B", "Hyperbolic: Qwen/Qwen2.5-72B-Instruct", "Hyperbolic: deepseek-ai/DeepSeek-V2.5", "Hyperbolic: meta-llama/Meta-Llama-3.1-405B-Instruct", ]
def generate_discussion_prompt(original_question: str, previous_responses: list[str]) -> str: """Generate a prompt for models to discuss and build upon previous responses. """ prompt = f"""You are participating in a multi-AI discussion about this question: "{original_question}"
Previous responses from other AI models:{chr(10).join(f"- {response}" for response in previous_responses)}
Please provide your perspective while:1. Acknowledging key insights from previous responses2. Adding any missing important points3. Respectfully noting if you disagree with anything and explaining why4. Building towards a complete answer
Keep your response focused and concise (max 3-4 paragraphs).""" return prompt
def generate_consensus_prompt(original_question: str, discussion_history: list[str]) -> str: """Generate a prompt for final consensus building.""" return f"""Review this multi-AI discussion about: "{original_question}"
Discussion history:{chr(10).join(discussion_history)}
As a final synthesizer, please:1. Identify the key points where all models agreed2. Explain how any disagreements were resolved3. Present a clear, unified answer that represents our collective best understanding4. Note any remaining uncertainties or caveats
Keep the final consensus concise but complete."""
def chat_with_openai(model: str, messages: list[dict], api_key: str | None) -> str: import openai
client = openai.OpenAI(api_key=api_key) response = client.chat.completions.create(model=model, messages=messages) return response.choices[0].message.content
def chat_with_anthropic(messages: list[dict], api_key: str | None) -> str: """Chat with Anthropic's Claude model.""" client = Anthropic(api_key=api_key) response = client.messages.create(model="claude-3-sonnet-20240229", messages=messages, max_tokens=1024) return response.content[0].text
def chat_with_gemini(messages: list[dict], api_key: str | None) -> str: """Chat with Gemini Pro model.""" genai.configure(api_key=api_key) model = genai.GenerativeModel("gemini-pro")
# Convert messages to Gemini format gemini_messages = [] for msg in messages: role = "user" if msg["role"] == "user" else "model" gemini_messages.append({"role": role, "parts": [msg["content"]]})
response = model.generate_content([m["parts"][0] for m in gemini_messages]) return response.text
def chat_with_sambanova( messages: list[dict], api_key: str | None, model_name: str = "Llama-3.2-90B-Vision-Instruct") -> str: """Chat with SambaNova's models using their OpenAI-compatible API.""" client = openai.OpenAI( api_key=api_key, base_url="https://api.sambanova.ai/v1", )
response = client.chat.completions.create( model=model_name, messages=messages, temperature=0.1, top_p=0.1, # Use the specific model name passed in ) return response.choices[0].message.content
def chat_with_hyperbolic( messages: list[dict], api_key: str | None, model_name: str = "Qwen/Qwen2.5-Coder-32B-Instruct") -> str: """Chat with Hyperbolic's models using their OpenAI-compatible API.""" client = OpenAI(api_key=api_key, base_url="https://api.hyperbolic.xyz/v1")
# Add system message to the start of the messages list full_messages = [ {"role": "system", "content": "You are a helpful assistant. Be descriptive and clear."}, *messages, ]
response = client.chat.completions.create( model=model_name, # Use the specific model name passed in messages=full_messages, temperature=0.7, max_tokens=1024, ) return response.choices[0].message.content
def multi_model_consensus( question: str, selected_models: list[str], rounds: int = 3, progress: gr.Progress = gr.Progress()) -> list[tuple[str, str]]: if not selected_models: raise gr.Error("Please select at least one model to chat with.")
chat_history = [] discussion_history = []
# Initial responses progress(0, desc="Getting initial responses...") initial_responses = [] for i, model in enumerate(selected_models): provider, model_name = model.split(": ", 1)
try: if provider == "Anthropic": api_key = os.getenv("ANTHROPIC_API_KEY") response = chat_with_anthropic(messages=[{"role": "user", "content": question}], api_key=api_key) elif provider == "SambaNova": api_key = os.getenv("SAMBANOVA_API_KEY") response = chat_with_sambanova( messages=[ {"role": "system", "content": "You are a helpful assistant"}, {"role": "user", "content": question}, ], api_key=api_key, ) elif provider == "Hyperbolic": # Add Hyperbolic case api_key = os.getenv("HYPERBOLIC_API_KEY") response = chat_with_hyperbolic(messages=[{"role": "user", "content": question}], api_key=api_key) else: # Gemini api_key = os.getenv("GEMINI_API_KEY") response = chat_with_gemini(messages=[{"role": "user", "content": question}], api_key=api_key)
initial_responses.append(f"{model}: {response}") discussion_history.append(f"Initial response from {model}:\n{response}") chat_history.append((f"Initial response from {model}", response)) except Exception as e: chat_history.append((f"Error from {model}", str(e)))
# Discussion rounds for round_num in range(rounds): progress((round_num + 1) / (rounds + 2), desc=f"Discussion round {round_num + 1}...") round_responses = []
random.shuffle(selected_models) # Randomize order each round for model in selected_models: provider, model_name = model.split(": ", 1)
try: discussion_prompt = generate_discussion_prompt(question, discussion_history) if provider == "Anthropic": api_key = os.getenv("ANTHROPIC_API_KEY") response = chat_with_anthropic( messages=[{"role": "user", "content": discussion_prompt}], api_key=api_key ) elif provider == "SambaNova": api_key = os.getenv("SAMBANOVA_API_KEY") response = chat_with_sambanova( messages=[ {"role": "system", "content": "You are a helpful assistant"}, {"role": "user", "content": discussion_prompt}, ], api_key=api_key, ) elif provider == "Hyperbolic": # Add Hyperbolic case api_key = os.getenv("HYPERBOLIC_API_KEY") response = chat_with_hyperbolic( messages=[{"role": "user", "content": discussion_prompt}], api_key=api_key ) else: # Gemini api_key = os.getenv("GEMINI_API_KEY") response = chat_with_gemini( messages=[{"role": "user", "content": discussion_prompt}], api_key=api_key )
round_responses.append(f"{model}: {response}") discussion_history.append(f"Round {round_num + 1} - {model}:\n{response}") chat_history.append((f"Round {round_num + 1} - {model}", response)) except Exception as e: chat_history.append((f"Error from {model} in round {round_num + 1}", str(e)))
# Final consensus progress(0.9, desc="Building final consensus...") model = selected_models[0] provider, model_name = model.split(": ", 1)
try: consensus_prompt = generate_consensus_prompt(question, discussion_history) if provider == "Anthropic": api_key = os.getenv("ANTHROPIC_API_KEY") final_consensus = chat_with_anthropic( messages=[{"role": "user", "content": consensus_prompt}], api_key=api_key ) elif provider == "SambaNova": api_key = os.getenv("SAMBANOVA_API_KEY") final_consensus = chat_with_sambanova( messages=[ {"role": "system", "content": "You are a helpful assistant"}, {"role": "user", "content": consensus_prompt}, ], api_key=api_key, ) elif provider == "Hyperbolic": # Add Hyperbolic case api_key = os.getenv("HYPERBOLIC_API_KEY") final_consensus = chat_with_hyperbolic( messages=[{"role": "user", "content": consensus_prompt}], api_key=api_key ) else: # Gemini api_key = os.getenv("GEMINI_API_KEY") final_consensus = chat_with_gemini( messages=[{"role": "user", "content": consensus_prompt}], api_key=api_key ) except Exception as e: final_consensus = f"Error getting consensus from {model}: {e!s}"
chat_history.append(("Final Consensus", final_consensus))
progress(1.0, desc="Done!") return chat_history
with gr.Blocks() as demo: gr.Markdown("# Experimental Multi-Model Consensus Chat") gr.Markdown( """Select multiple models to collaborate on answering your question. The models will discuss with each other and attempt to reach a consensus. Maximum 3 models can be selected at once.""" )
with gr.Row(): with gr.Column(): model_selector = gr.Dropdown( choices=get_all_models(), multiselect=True, label="Select Models (max 3)", info="Choose up to 3 models to participate in the discussion", value=["SambaNova: Llama-3.2-90B-Vision-Instruct", "Hyperbolic: Qwen/Qwen2.5-Coder-32B-Instruct"], max_choices=3, ) rounds_slider = gr.Slider( minimum=1, maximum=2, value=1, step=1, label="Discussion Rounds", info="Number of rounds of discussion between models", )
chatbot = gr.Chatbot(height=600, label="Multi-Model Discussion") msg = gr.Textbox(label="Your Question", placeholder="Ask a question for the models to discuss...")
def respond(message, selected_models, rounds): chat_history = multi_model_consensus(message, selected_models, rounds) return chat_history
msg.submit(respond, [msg, model_selector, rounds_slider], [chatbot], api_name="consensus_chat")
for fn in demo.fns.values(): fn.api_name = False
if __name__ == "__main__": demo.launch()12345678910111213141516import fal_gradio
from utils import get_app
demo = get_app( models=[ "fal-ai/ltx-video", "fal-ai/ltx-video/image-to-video", "fal-ai/luma-photon", ], default_model="fal-ai/luma-photon", src=fal_gradio.registry,)
if __name__ == "__main__": demo.launch()12345678910111213141516171819import os
import fireworks_gradio
from utils import get_app
demo = get_app( models=[ "f1-preview", "f1-mini-preview", "llama-v3p3-70b-instruct", ], default_model="llama-v3p3-70b-instruct", src=fireworks_gradio.registry, accept_token=not os.getenv("FIREWORKS_API_KEY"),)
if __name__ == "__main__": demo.launch()12345678910111213141516171819202122import ai_gradio
from utils_ai_gradio import get_app
# Get the Gemini models but keep their full names for loadingGEMINI_MODELS_FULL = [k for k in ai_gradio.registry if k.startswith("gemini:")]
# Create display names without the prefixGEMINI_MODELS_DISPLAY = [k.replace("gemini:", "") for k in GEMINI_MODELS_FULL]
# Create and launch the interface using get_app utilitydemo = get_app( models=GEMINI_MODELS_FULL, # Use the full names with prefix default_model=GEMINI_MODELS_FULL[-1], dropdown_label="Select Gemini Model", choices=GEMINI_MODELS_DISPLAY, # Display names without prefix src=ai_gradio.registry, fill_height=True,)
if __name__ == "__main__": demo.launch()1234567891011121314151617181920212223import ai_gradio
from utils_ai_gradio import get_app
# Get the Gemini models but keep their full names for loadingGEMINI_MODELS_FULL = [k for k in ai_gradio.registry if k.startswith("gemini:")]
# Create display names without the prefixGEMINI_MODELS_DISPLAY = [k.replace("gemini:", "") for k in GEMINI_MODELS_FULL]
# Create and launch the interface using get_app utilitydemo = get_app( models=GEMINI_MODELS_FULL, # Use the full names with prefix default_model=GEMINI_MODELS_FULL[-2], dropdown_label="Select Gemini Model", choices=GEMINI_MODELS_DISPLAY, # Display names without prefix src=ai_gradio.registry, camera=True, fill_height=True,)
if __name__ == "__main__": demo.launch()1234567891011121314151617181920212223import ai_gradio
from utils_ai_gradio import get_app
# Get the Gemini models but keep their full names for loadingGEMINI_MODELS_FULL = [k for k in ai_gradio.registry if k.startswith("gemini:")]
# Create display names without the prefixGEMINI_MODELS_DISPLAY = [k.replace("gemini:", "") for k in GEMINI_MODELS_FULL]
# Create and launch the interface using get_app utilitydemo = get_app( models=GEMINI_MODELS_FULL, # Use the full names with prefix default_model=GEMINI_MODELS_FULL[0], dropdown_label="Select Gemini Model", choices=GEMINI_MODELS_DISPLAY, # Display names without prefix src=ai_gradio.registry, fill_height=True, coder=True,)
if __name__ == "__main__": demo.launch()1234567891011121314151617181920212223import ai_gradio
from utils_ai_gradio import get_app
# Get the Gemini models but keep their full names for loadingGEMINI_MODELS_FULL = [k for k in ai_gradio.registry if k.startswith("gemini:")]
# Create display names without the prefixGEMINI_MODELS_DISPLAY = [k.replace("gemini:", "") for k in GEMINI_MODELS_FULL]
# Create and launch the interface using get_app utilitydemo = get_app( models=GEMINI_MODELS_FULL, # Use the full names with prefix default_model=GEMINI_MODELS_FULL[-2], dropdown_label="Select Gemini Model", choices=GEMINI_MODELS_DISPLAY, # Display names without prefix src=ai_gradio.registry, enable_voice=True, fill_height=True,)
if __name__ == "__main__": demo.launch()123456789101112131415161718192021import ai_gradio
from utils_ai_gradio import get_app
# Get the Groq models from the registryGROQ_MODELS_FULL = [k for k in ai_gradio.registry.keys() if k.startswith("groq:")]
# Create display names without the prefixGROQ_MODELS_DISPLAY = [k.replace("groq:", "") for k in GROQ_MODELS_FULL]
demo = get_app( models=GROQ_MODELS_FULL, default_model=GROQ_MODELS_FULL[-2], src=ai_gradio.registry, dropdown_label="Select Groq Model", choices=GROQ_MODELS_DISPLAY, fill_height=True,)
if __name__ == "__main__": demo.launch()1234567891011121314151617181920212223import ai_gradio
from utils_ai_gradio import get_app
# Get the Groq models but keep their full names for loadingGROQ_MODELS_FULL = [k for k in ai_gradio.registry.keys() if k.startswith("groq:")]
# Create display names without the prefixGROQ_MODELS_DISPLAY = [k.replace("groq:", "") for k in GROQ_MODELS_FULL]
# Create and launch the interface using get_app utilitydemo = get_app( models=GROQ_MODELS_FULL, # Use the full names with prefix default_model=GROQ_MODELS_FULL[-1], dropdown_label="Select Groq Model", choices=GROQ_MODELS_DISPLAY, # Display names without prefix fill_height=True, coder=True,)
if __name__ == "__main__": demo.launch()1234567891011121314151617from utils import get_app
demo = get_app( models=[ "microsoft/Phi-3.5-mini-instruct", "HuggingFaceTB/SmolLM2-1.7B-Instruct", "google/gemma-2-2b-it", "openai-community/gpt2", "microsoft/phi-2", "TinyLlama/TinyLlama-1.1B-Chat-v1.0", ], default_model="HuggingFaceTB/SmolLM2-1.7B-Instruct", src="models",)
if __name__ == "__main__": demo.launch()12345678910111213141516171819202122import ai_gradio
from utils_ai_gradio import get_app
# Get the hyperbolic models but keep their full names for loadingHUGGINGFACE_MODELS_FULL = [k for k in ai_gradio.registry.keys() if k.startswith("huggingface:")]
# Create display names without the prefixHUGGINGFACE_MODELS_DISPLAY = [k.replace("huggingface:", "") for k in HUGGINGFACE_MODELS_FULL]
# Create and launch the interface using get_app utilitydemo = get_app( models=HUGGINGFACE_MODELS_FULL, # Use the full names with prefix default_model=HUGGINGFACE_MODELS_FULL[0], dropdown_label="Select Huggingface Model", choices=HUGGINGFACE_MODELS_DISPLAY, # Display names without prefix fill_height=True, coder=True, provider="fireworks-ai", bill_to="huggingface")12345678910111213141516171819import ai_gradio
from utils_ai_gradio import get_app
# Get the hyperbolic models but keep their full names for loadingHYPERBOLIC_MODELS_FULL = [k for k in ai_gradio.registry.keys() if k.startswith("hyperbolic:")]
# Create display names without the prefixHYPERBOLIC_MODELS_DISPLAY = [k.replace("hyperbolic:", "") for k in HYPERBOLIC_MODELS_FULL]
# Create and launch the interface using get_app utilitydemo = get_app( models=HYPERBOLIC_MODELS_FULL, # Use the full names with prefix default_model=HYPERBOLIC_MODELS_FULL[-2], dropdown_label="Select Hyperbolic Model", choices=HYPERBOLIC_MODELS_DISPLAY, # Display names without prefix fill_height=True,)1234567891011121314151617181920import ai_gradio
from utils_ai_gradio import get_app
# Get the hyperbolic models but keep their full names for loadingHYPERBOLIC_MODELS_FULL = [k for k in ai_gradio.registry.keys() if k.startswith("hyperbolic:")]
# Create display names without the prefixHYPERBOLIC_MODELS_DISPLAY = [k.replace("hyperbolic:", "") for k in HYPERBOLIC_MODELS_FULL]
# Create and launch the interface using get_app utilitydemo = get_app( models=HYPERBOLIC_MODELS_FULL, # Use the full names with prefix default_model=HYPERBOLIC_MODELS_FULL[-2], dropdown_label="Select Hyperbolic Model", choices=HYPERBOLIC_MODELS_DISPLAY, # Display names without prefix fill_height=True, coder=True,)1234567891011121314151617181920212223import ai_gradio
from utils_ai_gradio import get_app
# Get the hyperbolic models but keep their full names for loadingLANGCHAIN_MODELS_FULL = [k for k in ai_gradio.registry.keys() if k.startswith("langchain:")]
# Create display names without the prefixLANGCHAIN_MODELS_DISPLAY = [k.replace("langchain:", "") for k in LANGCHAIN_MODELS_FULL]
# Create and launch the interface using get_app utilitydemo = get_app( models=LANGCHAIN_MODELS_FULL, # Use the full names with prefix default_model=LANGCHAIN_MODELS_FULL[0], dropdown_label="Select Langchain Model", choices=LANGCHAIN_MODELS_DISPLAY, # Display names without prefix fill_height=True,)
if __name__ == "__main__": demo.launch()
1234567import gradio as grimport lumaai_gradio
demo = gr.load( name="dream-machine", src=lumaai_gradio.registry,)123456789101112import gradio as grimport spacesimport transformers_gradio
demo = gr.load(name="AIDC-AI/Marco-o1", src=transformers_gradio.registry)demo.fn = spaces.GPU()(demo.fn)
for fn in demo.fns.values(): fn.api_name = False
if __name__ == "__main__": demo.launch()123456import gradio as gr
demo = gr.load("models/meta-llama/Llama-3.3-70B-Instruct")
if __name__ == "__main__": demo.launch()123456789101112import gradio as gr
# Load the Gradio spacedemo = gr.load(name="internlm/MindSearch", src="spaces")
# Disable API access for all functionsif hasattr(demo, "fns"): for fn in demo.fns.values(): fn.api_name = False
if __name__ == "__main__": demo.launch()12345678910111213141516171819202122import ai_gradio
from utils_ai_gradio import get_app
# Get the hyperbolic models but keep their full names for loadingMINIMAX_MODELS_FULL = [k for k in ai_gradio.registry.keys() if k.startswith("minimax:")]
# Create display names without the prefixMINIMAX_MODELS_DISPLAY = [k.replace("minimax:", "") for k in MINIMAX_MODELS_FULL]
# Create and launch the interface using get_app utilitydemo = get_app( models=MINIMAX_MODELS_FULL, # Use the full names with prefix default_model=MINIMAX_MODELS_FULL[0], dropdown_label="Select Minimax Model", choices=MINIMAX_MODELS_DISPLAY, # Display names without prefix fill_height=True,)
if __name__ == "__main__": demo.launch()1234567891011121314151617181920212223import ai_gradio
from utils_ai_gradio import get_app
# Get the hyperbolic models but keep their full names for loadingMINIMAX_MODELS_FULL = [k for k in ai_gradio.registry.keys() if k.startswith("minimax:")]
# Create display names without the prefixMINIMAX_MODELS_DISPLAY = [k.replace("minimax:", "") for k in MINIMAX_MODELS_FULL]
# Create and launch the interface using get_app utilitydemo = get_app( models=MINIMAX_MODELS_FULL, # Use the full names with prefix default_model=MINIMAX_MODELS_FULL[0], dropdown_label="Select Minimax Model", choices=MINIMAX_MODELS_DISPLAY, # Display names without prefix fill_height=True, coder=True)
if __name__ == "__main__": demo.launch()1234567891011121314151617181920212223import ai_gradio
from utils_ai_gradio import get_app
# Get the mistral models but keep their full names for loadingMISTRAL_MODELS_FULL = [k for k in ai_gradio.registry.keys() if k.startswith("mistral:")]
# Create display names without the prefixMISTRAL_MODELS_DISPLAY = [k.replace("mistral:", "") for k in MISTRAL_MODELS_FULL]
# Create and launch the interface using get_app utilitydemo = get_app( models=MISTRAL_MODELS_FULL, # Use the full names with prefix default_model=MISTRAL_MODELS_FULL[5], dropdown_label="Select Mistral Model", choices=MISTRAL_MODELS_DISPLAY, # Display names without prefix fill_height=True, coder=True)
if __name__ == "__main__": demo.launch()12345678910111213import gradio as gr
# Load the Gradio spacedemo = gr.load(name="akhaliq/moondream", src="spaces")
# Disable API access for all functionsif hasattr(demo, "fns"): for fn in demo.fns.values(): fn.api_name = False
if __name__ == "__main__": demo.launch()12345678910111213141516171819202122import ai_gradio
from utils_ai_gradio import get_app
# Get the nvidia models but keep their full names for loadingNVIDIA_MODELS_FULL = [k for k in ai_gradio.registry.keys() if k.startswith("nvidia:")]
# Create display names without the prefixNVIDIA_MODELS_DISPLAY = [k.replace("nvidia:", "") for k in NVIDIA_MODELS_FULL]
# Create and launch the interface using get_app utilitydemo = get_app( models=NVIDIA_MODELS_FULL, # Use the full names with prefix default_model=NVIDIA_MODELS_FULL[0], dropdown_label="Select Nvidia Model", choices=NVIDIA_MODELS_DISPLAY, # Display names without prefix fill_height=True,)
if __name__ == "__main__": demo.launch()1234567891011121314151617181920212223import ai_gradio
from utils_ai_gradio import get_app
# Get the nvidia models but keep their full names for loadingNVIDIA_MODELS_FULL = [k for k in ai_gradio.registry.keys() if k.startswith("nvidia:")]
# Create display names without the prefixNVIDIA_MODELS_DISPLAY = [k.replace("nvidia:", "") for k in NVIDIA_MODELS_FULL]
# Create and launch the interface using get_app utilitydemo = get_app( models=NVIDIA_MODELS_FULL, # Use the full names with prefix default_model=NVIDIA_MODELS_FULL[-1], dropdown_label="Select Nvidia Model", choices=NVIDIA_MODELS_DISPLAY, # Display names without prefix fill_height=True, coder=True)
if __name__ == "__main__": demo.launch()12345678910import gradio as gr
# Load the Gradio spacedemo = gr.load(name="Yuanshi/OminiControl", src="spaces")
# Disable API access for all functionsif hasattr(demo, "fns"): for fn in demo.fns.values(): fn.api_name = False123456789101112131415161718192021import ai_gradio
from utils_ai_gradio import get_app
# Get the OpenAI models but keep their full names for loadingOPENAI_MODELS_FULL = [k for k in ai_gradio.registry.keys() if k.startswith("openai:")]
# Create display names without the prefixOPENAI_MODELS_DISPLAY = [k.replace("openai:", "") for k in OPENAI_MODELS_FULL]
# Create and launch the interface using get_app utilitydemo = get_app( models=OPENAI_MODELS_FULL, # Use the full names with prefix default_model=OPENAI_MODELS_FULL[-1], dropdown_label="Select OpenAI Model", choices=OPENAI_MODELS_DISPLAY, # Display names without prefix fill_height=True,)
if __name__ == "__main__": demo.launch()12345678910111213141516171819202122import ai_gradio
from utils_ai_gradio import get_app
# Get the OpenAI models but keep their full names for loadingOPENAI_MODELS_FULL = [k for k in ai_gradio.registry.keys() if k.startswith("openai:")]
# Create display names without the prefixOPENAI_MODELS_DISPLAY = [k.replace("openai:", "") for k in OPENAI_MODELS_FULL]
# Create and launch the interface using get_app utilitydemo = get_app( models=OPENAI_MODELS_FULL, # Use the full names with prefix default_model=OPENAI_MODELS_FULL[-1], dropdown_label="Select OpenAI Model", choices=OPENAI_MODELS_DISPLAY, # Display names without prefix fill_height=True, coder=True,)
if __name__ == "__main__": demo.launch()1234567891011121314151617181920212223import os
import openai_gradio
from utils import get_app
demo = get_app( models=[ "gpt-4o-realtime-preview", "gpt-4o-realtime-preview-2024-12-17", "gpt-4o-realtime-preview-2024-10-01", "gpt-4o-mini-realtime-preview", "gpt-4o-mini-realtime-preview-2024-12-17", ], default_model="gpt-4o-mini-realtime-preview-2024-12-17", src=openai_gradio.registry, accept_token=not os.getenv("OPENAI_API_KEY"), twilio_sid=os.getenv("TWILIO_SID_OPENAI"), twilio_token=os.getenv("TWILIO_AUTH_OPENAI"),)
if __name__ == "__main__": demo.launch()12345678910111213141516171819202122import ai_gradio
from utils_ai_gradio import get_app
# Get the OpenAI models but keep their full names for loadingOPENROUTER_MODELS_FULL = [k for k in ai_gradio.registry.keys() if k.startswith("openrouter:")]
# Create display names without the prefixOPENROUTER_MODELS_DISPLAY = [k.replace("openrouter:", "") for k in OPENROUTER_MODELS_FULL]
# Create and launch the interface using get_app utilitydemo = get_app( models=OPENROUTER_MODELS_FULL, # Use the full names with prefix default_model=OPENROUTER_MODELS_FULL[-1], dropdown_label="Select OpenRouter Model", choices=OPENROUTER_MODELS_DISPLAY, # Display names without prefix fill_height=True, coder=True,)
if __name__ == "__main__": demo.launch()123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778import gradio as grfrom gradio_client import Client, handle_file
MODELS = {"Paligemma-10B": "akhaliq/paligemma2-10b-ft-docci-448"}
def create_chat_fn(client, system_prompt, temperature, max_tokens, top_k, rep_penalty, top_p): def chat(message, history): text = message.get("text", "") files = message.get("files", []) processed_files = [handle_file(f) for f in files]
response = client.predict( message={"text": text, "files": processed_files}, system_prompt=system_prompt, temperature=temperature, max_new_tokens=max_tokens, top_k=top_k, repetition_penalty=rep_penalty, top_p=top_p, api_name="/chat", ) return response
return chat
def set_client_for_session(model_name, request: gr.Request): headers = {} if request and hasattr(request, "headers"): x_ip_token = request.headers.get("x-ip-token") if x_ip_token: headers["X-IP-Token"] = x_ip_token
return Client(MODELS[model_name], headers=headers)
def safe_chat_fn(message, history, client, system_prompt, temperature, max_tokens, top_k, rep_penalty, top_p): if client is None: return "Error: Client not initialized. Please refresh the page." try: return create_chat_fn(client, system_prompt, temperature, max_tokens, top_k, rep_penalty, top_p)( message, history ) except Exception as e: print(f"Error during chat: {e!s}") return f"Error during chat: {e!s}"
with gr.Blocks() as demo: client = gr.State()
with gr.Accordion("Advanced Settings", open=False): system_prompt = gr.Textbox(value="You are a helpful AI assistant.", label="System Prompt") with gr.Row(): temperature = gr.Slider(minimum=0.0, maximum=2.0, value=0.7, label="Temperature") top_p = gr.Slider(minimum=0.0, maximum=1.0, value=0.95, label="Top P") with gr.Row(): top_k = gr.Slider(minimum=1, maximum=100, value=40, step=1, label="Top K") rep_penalty = gr.Slider(minimum=1.0, maximum=2.0, value=1.1, label="Repetition Penalty") max_tokens = gr.Slider(minimum=64, maximum=4096, value=1024, step=64, label="Max Tokens")
chat_interface = gr.ChatInterface( fn=safe_chat_fn, additional_inputs=[client, system_prompt, temperature, max_tokens, top_k, rep_penalty, top_p], multimodal=True, )
# Initialize client on page load with default model demo.load(fn=set_client_for_session, inputs=[gr.State("Paligemma-10B")], outputs=[client]) # Using default model
# Move the API access check here, after demo is definedif hasattr(demo, "fns"): for fn in demo.fns.values(): fn.api_name = False
if __name__ == "__main__": demo.launch()1234567891011121314151617181920212223import os
import perplexity_gradio
from utils import get_app
demo = get_app( models=[ "llama-3.1-sonar-large-128k-online", "llama-3.1-sonar-small-128k-online", "llama-3.1-sonar-huge-128k-online", "llama-3.1-sonar-small-128k-chat", "llama-3.1-sonar-large-128k-chat", "llama-3.1-8b-instruct", "llama-3.1-70b-instruct", ], default_model="llama-3.1-sonar-huge-128k-online", src=perplexity_gradio.registry, accept_token=not os.getenv("PERPLEXITY_API_KEY"),)
if __name__ == "__main__": demo.launch()12345678910import gradio as grimport playai_gradio
demo = gr.load( name="PlayDialog", src=playai_gradio.registry,)
for fn in demo.fns.values(): fn.api_name = False12345678910111213141516171819import ai_gradio
from utils_ai_gradio import get_app
# Get the qwen models but keep their full names for loadingQWEN_MODELS_FULL = [k for k in ai_gradio.registry.keys() if k.startswith("qwen:")]
# Create display names without the prefixQWEN_MODELS_DISPLAY = [k.replace("qwen:", "") for k in QWEN_MODELS_FULL]
# Create and launch the interface using get_app utilitydemo = get_app( models=QWEN_MODELS_FULL, # Use the full names with prefix default_model=QWEN_MODELS_FULL[-1], dropdown_label="Select Qwen Model", choices=QWEN_MODELS_DISPLAY, # Display names without prefix fill_height=True,)1234567891011121314151617181920import ai_gradio
from utils_ai_gradio import get_app
# Get the qwen models but keep their full names for loadingQWEN_MODELS_FULL = [k for k in ai_gradio.registry.keys() if k.startswith("qwen:")]
# Create display names without the prefixQWEN_MODELS_DISPLAY = [k.replace("qwen:", "") for k in QWEN_MODELS_FULL]
# Create and launch the interface using get_app utilitydemo = get_app( models=QWEN_MODELS_FULL, # Use the full names with prefix default_model=QWEN_MODELS_FULL[-1], dropdown_label="Select Qwen Model", choices=QWEN_MODELS_DISPLAY, # Display names without prefix fill_height=True, coder=True,).gitattributesDeleted-35
.gitignore+20-101
.pre-commit-config.yamlDeleted-32
.python-versionDeleted-1
.vscode/extensions.jsonDeleted-8
.vscode/settings.jsonDeleted-16
README.md+80-1
app.cssAdded+59
app.py+288-50
app_allenai.pyDeleted-67
app_cerebras.pyDeleted-19
app_claude.pyDeleted-21
app_cohere.pyDeleted-21
app_compare.pyDeleted-210
app_crew.pyDeleted-8
app_deepseek.pyDeleted-23
app_experimental.pyDeleted-300
app_fal.pyDeleted-16
app_fireworks.pyDeleted-19
app_gemini.pyDeleted-22
app_gemini_camera.pyDeleted-23
app_gemini_coder.pyDeleted-23
app_gemini_voice.pyDeleted-23
app_groq.pyDeleted-21
app_groq_coder.pyDeleted-23
app_hf.pyDeleted-17
app_huggingface.pyDeleted-22
app_hyperbolic.pyDeleted-19
app_hyperbolic_coder.pyDeleted-20
app_langchain.pyDeleted-23
app_lumaai.pyDeleted-7
app_marco_o1.pyDeleted-12
app_meta.pyDeleted-6
app_mindsearch.pyDeleted-12
app_minimax.pyDeleted-22
app_minimax_coder.pyDeleted-23
app_mistral.pyDeleted-23
app_moondream.pyDeleted-13
app_nvidia.pyDeleted-22
app_nvidia_coder.pyDeleted-23
app_omini.pyDeleted-10
app_openai.pyDeleted-21
app_openai_coder.pyDeleted-22
app_openai_voice.pyDeleted-23
app_openrouter.pyDeleted-22
app_paligemma.pyDeleted-78
app_perplexity.pyDeleted-23
app_playai.pyDeleted-10
app_qwen.pyDeleted-19
app_qwen_coder.pyDeleted-20