ruff
Browse filesFiles changed (17)
- app_allenai.py-1
- app_compare.py+16-16
- app_crew.py+4-4
- app_deepseek.py+3-3
- app_experimental.py+15-12
- app_groq.py+3-11
- app_groq_coder.py+4-9
- app_huggingface.py+2-3
- app_hyperbolic.py+4-10
- app_hyperbolic_coder.py+4-10
- app_openai.py+3-9
- app_openai_coder.py+3-9
- app_paligemma.py+2-2
- app_smolagents.py+3-8
- app_transformers.py+1-8
- pyproject.toml+1
- utils.py+4-3
37 unmodified lines3839404141424337 unmodified lines
with gr.Blocks() as demo:
client = gr.State()
model_dropdown = gr.Dropdown(12323424 unmodified lines2930313432333634353637389 unmodified lines48495052515253549 unmodified lines64656668676869701 unmodified line727374767576777879808183828384859 unmodified lines9596979998991001012 unmodified lines10410510610810710810911011111211311411511411611711811914 unmodified lines13413513613513713813914033 unmodified lines1741751761751771781791801 unmodified line182183184183184185185186187188import osimport randomfrom typing import Dict, List
import google.generativeai as genaiimport gradio as gr24 unmodified lines ]
def generate_discussion_prompt(original_question: str, previous_responses: List[str]) -> str:def generate_discussion_prompt(original_question: str, previous_responses: list[str]) -> str: """Generate a prompt for models to discuss and build upon previous responses.""" responses. """ prompt = f"""You are participating in a multi-AI discussion about this question: "{original_question}"
Previous responses from other AI models:9 unmodified lines return prompt
def generate_consensus_prompt(original_question: str, discussion_history: List[str]) -> str: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}"
9 unmodified linesKeep the final consensus concise but complete."""
def chat_with_openai(model: str, messages: List[Dict], api_key: str | None) -> str:def chat_with_openai(model: str, messages: list[dict], api_key: str | None) -> str: import openai
client = openai.OpenAI(api_key=api_key)1 unmodified line return response.choices[0].message.content
def chat_with_anthropic(messages: List[Dict], api_key: str | None) -> str: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: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")9 unmodified lines
def chat_with_sambanova( messages: List[Dict], api_key: str | None, model_name: str = "Llama-3.2-90B-Vision-Instruct" 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(2 unmodified lines )
response = client.chat.completions.create( model=model_name, messages=messages, temperature=0.1, top_p=0.1 # Use the specific model name passed in 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" 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")14 unmodified lines
def multi_model_consensus( question: str, selected_models: List[str], rounds: int = 3, progress: gr.Progress = gr.Progress() 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.")33 unmodified lines
chat_history.append((model, response)) except Exception as e: chat_history.append((model, f"Error: {str(e)}")) chat_history.append((model, f"Error: {e!s}"))
progress(1.0, desc="Done!") return chat_history1 unmodified line
with gr.Blocks() as demo: gr.Markdown("# Model Response Comparison") gr.Markdown( """Select multiple models to compare their responses""" ) gr.Markdown("""Select multiple models to compare their responses""")
with gr.Row(): with gr.Column():112345656788import gradio as grimport ai_gradioimport gradio as gr
demo = gr.load( name='crewai:gpt-4-turbo', crew_type='article', # or 'support' name="crewai:gpt-4-turbo", crew_type="article", # or 'support' src=ai_gradio.registry,))1123455677import gradio as grimport ai_gradioimport gradio as gr
demo = gr.load( name='deepseek:deepseek-chat', name="deepseek:deepseek-chat", src=ai_gradio.registry,))12334524 unmodified lines3031323433343635363738399 unmodified lines49505152525354559 unmodified lines65666768686970711 unmodified line737475767677787980818283838485869 unmodified lines96979899991001011022 unmodified lines10510610710810810911011111211311411511611411711811912014 unmodified lines135136137135138139140141107 unmodified lines249250251249252253254255import osimport randomfrom typing import Dict, List
import google.generativeai as genaiimport gradio as gr24 unmodified lines ]
def generate_discussion_prompt(original_question: str, previous_responses: List[str]) -> str:def generate_discussion_prompt(original_question: str, previous_responses: list[str]) -> str: """Generate a prompt for models to discuss and build upon previous responses.""" responses. """ prompt = f"""You are participating in a multi-AI discussion about this question: "{original_question}"
Previous responses from other AI models:9 unmodified lines return prompt
def generate_consensus_prompt(original_question: str, discussion_history: List[str]) -> str: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}"
9 unmodified linesKeep the final consensus concise but complete."""
def chat_with_openai(model: str, messages: List[Dict], api_key: str | None) -> str:def chat_with_openai(model: str, messages: list[dict], api_key: str | None) -> str: import openai
client = openai.OpenAI(api_key=api_key)1 unmodified line return response.choices[0].message.content
def chat_with_anthropic(messages: List[Dict], api_key: str | None) -> str: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: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")9 unmodified lines
def chat_with_sambanova( messages: List[Dict], api_key: str | None, model_name: str = "Llama-3.2-90B-Vision-Instruct" 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(2 unmodified lines )
response = client.chat.completions.create( model=model_name, messages=messages, temperature=0.1, top_p=0.1 # Use the specific model name passed in 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" 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")14 unmodified lines
def multi_model_consensus( question: str, selected_models: List[str], rounds: int = 3, progress: gr.Progress = gr.Progress() 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.")107 unmodified lines messages=[{"role": "user", "content": consensus_prompt}], api_key=api_key ) except Exception as e: final_consensus = f"Error getting consensus from {model}: {str(e)}" final_consensus = f"Error getting consensus from {model}: {e!s}"
chat_history.append(("Final Consensus", final_consensus))
12123458910116781415161791011121 unmodified line1415162517181920import os
import 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:')]GROQ_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]GROQ_MODELS_DISPLAY = [k.replace("groq:", "") for k in GROQ_MODELS_FULL]
demo = get_app( models=GROQ_MODELS_FULL,1 unmodified line src=ai_gradio.registry, dropdown_label="Select Groq Model", choices=GROQ_MODELS_DISPLAY, fill_height=True fill_height=True,)
if __name__ == "__main__":1234556786781112131491011122 unmodified lines1516172318192021import 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:')]GROQ_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]GROQ_MODELS_DISPLAY = [k.replace("groq:", "") for k in GROQ_MODELS_FULL]
# Create and launch the interface using get_app utilitydemo = get_app(2 unmodified lines dropdown_label="Select Groq Model", choices=GROQ_MODELS_DISPLAY, # Display names without prefix fill_height=True, coder=True coder=True,)
43 unmodified lines444546474847484950515252535443 unmodified lines try: return create_chat_fn(client)(message, history) except Exception as e: print(f"Error during chat: {str(e)}") return f"Error during chat: {str(e)}" print(f"Error during chat: {e!s}") return f"Error during chat: {e!s}"
with gr.Blocks() as demo:
client = gr.State()
model_dropdown = gr.Dropdown(1234556786781112131491011122 unmodified lines15161723181925import 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:')]HYPERBOLIC_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]HYPERBOLIC_MODELS_DISPLAY = [k.replace("hyperbolic:", "") for k in HYPERBOLIC_MODELS_FULL]
# Create and launch the interface using get_app utility2 unmodified lines default_model=HYPERBOLIC_MODELS_FULL[-1], dropdown_label="Select Hyperbolic Model", choices=HYPERBOLIC_MODELS_DISPLAY, # Display names without prefix fill_height=True fill_height=True,)
1234556786781112131491011123 unmodified lines16171824192026import 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:')]HYPERBOLIC_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]HYPERBOLIC_MODELS_DISPLAY = [k.replace("hyperbolic:", "") for k in HYPERBOLIC_MODELS_FULL]
# Create and launch the interface using get_app utility3 unmodified lines dropdown_label="Select Hyperbolic Model", choices=HYPERBOLIC_MODELS_DISPLAY, # Display names without prefix fill_height=True, coder=True coder=True,)
1223456789678121314159101112import ai_gradiofrom utils_ai_gradio import get_app
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:')]OPENAI_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]OPENAI_MODELS_DISPLAY = [k.replace("openai:", "") for k in OPENAI_MODELS_FULL]
# Create and launch the interface using get_app utilitydemo = get_app(1223456789678121314159101112import ai_gradiofrom utils_ai_gradio import get_app
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:')]OPENAI_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]OPENAI_MODELS_DISPLAY = [k.replace("openai:", "") for k in OPENAI_MODELS_FULL]
# Create and launch the interface using get_app utilitydemo = get_app(42 unmodified lines4344454647464748495042 unmodified lines message, history ) except Exception as e: print(f"Error during chat: {str(e)}") return f"Error during chat: {str(e)}" print(f"Error during chat: {e!s}") return f"Error during chat: {e!s}"
with gr.Blocks() as demo:1234456756710111213891011import ai_gradio
from utils_ai_gradio import get_app
SMOLAGENTS_MODELS_FULL = [ k for k in ai_gradio.registry.keys() if k.startswith('smolagents:')]SMOLAGENTS_MODELS_FULL = [k for k in ai_gradio.registry.keys() if k.startswith("smolagents:")]
SMOLAGENTS_MODELS_DISPLAY = [ k.replace('smolagents:', '') for k in SMOLAGENTS_MODELS_FULL]SMOLAGENTS_MODELS_DISPLAY = [k.replace("smolagents:", "") for k in SMOLAGENTS_MODELS_FULL]
demo = get_app( models=SMOLAGENTS_MODELS_FULL, # Use the full names with prefix12345634562 unmodified lines9101115161718import gradio as gr
demo = gr.load( name='akhaliq/phi-4', src="spaces")demo = gr.load(name="akhaliq/phi-4", src="spaces")
# Disable API access for all functionsif hasattr(demo, "fns"):2 unmodified lines
if __name__ == "__main__": demo.launch()
58 unmodified lines5960616263646558 unmodified lines
[tool.ruff.lint]select = ["E", "F", "I", "N", "S", "T", "UP", "W"]ignore = ["T201"]
[tool.ruff.format]docstring-code-format = true1123451 unmodified line78991011121324 unmodified lines3839404041from typing import Callable, Dict, Literal, Unionfrom collections.abc import Callablefrom typing import Literal
import gradio as gr
1 unmodified linedef get_app( models: list[str], default_model: str, src: Union[Callable[[str, str | None], gr.Blocks], Literal["models"], Dict[str, gr.Blocks]], src: Callable[[str, str | None], gr.Blocks] | Literal["models"] | dict[str, gr.Blocks], accept_token: bool = False, dropdown_label: str = "Select Model", **kwargs,24 unmodified lines for fn in demo.fns.values(): fn.api_name = False
return demo return demoapp_allenai.py-1
app_compare.py+16-16
app_crew.py+4-4
app_deepseek.py+3-3
app_experimental.py+15-12
app_groq.py+3-11
app_groq_coder.py+4-9
app_huggingface.py+2-3
app_hyperbolic.py+4-10
app_hyperbolic_coder.py+4-10
app_openai.py+3-9
app_openai_coder.py+3-9
app_paligemma.py+2-2
app_smolagents.py+3-8
app_transformers.py+1-8
pyproject.toml+1
utils.py+4-3