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 lines3839404142434437 unmodified lineswith gr.Blocks() as demo:client = gr.State()model_dropdown = gr.Dropdown(37 unmodified lines38394041424337 unmodified lineswith gr.Blocks() as demo:client = gr.State()model_dropdown = gr.Dropdown(
12345624 unmodified lines3132333435363738399 unmodified lines495051525354559 unmodified lines656667686970711 unmodified line73747576777879808182838485869 unmodified lines969798991001011022 unmodified lines10510610710810911011111211311411511611714 unmodified lines13213313413513613713833 unmodified lines1721731741751761771781 unmodified line180181182183184185186187188import osimport randomfrom typing import Dict, Listimport google.generativeai as genaiimport gradio as gr24 unmodified lines]def generate_discussion_prompt(original_question: str, previous_responses: List[str]) -> str:"""Generate a prompt for models to discuss and build upon previousresponses."""prompt = f"""You are participating in a multi-AI discussion about this question: "{original_question}"Previous responses from other AI models:9 unmodified linesreturn promptdef 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:import openaiclient = openai.OpenAI(api_key=api_key)1 unmodified linereturn response.choices[0].message.contentdef 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].textdef 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 linesdef 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(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)return response.choices[0].message.contentdef 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")14 unmodified linesdef 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.")33 unmodified lineschat_history.append((model, response))except Exception as e:chat_history.append((model, f"Error: {str(e)}"))progress(1.0, desc="Done!")return chat_history1 unmodified linewith gr.Blocks() as demo:gr.Markdown("# Model Response Comparison")gr.Markdown("""Select multiple models to compare their responses""")with gr.Row():with gr.Column():123424 unmodified lines293031323334353637389 unmodified lines484950515253549 unmodified lines646566676869701 unmodified line72737475767778798081828384859 unmodified lines95969798991001012 unmodified lines10410510610710810911011111211311411511611711811914 unmodified lines13413513613713813914033 unmodified lines1741751761771781791801 unmodified line182183184185186187188import osimport google.generativeai as genaiimport gradio as gr24 unmodified lines]def generate_discussion_prompt(original_question: str, previous_responses: list[str]) -> str:"""Generate a prompt for models to discuss and build upon previousresponses."""prompt = f"""You are participating in a multi-AI discussion about this question: "{original_question}"Previous responses from other AI models:9 unmodified linesreturn promptdef 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:import openaiclient = openai.OpenAI(api_key=api_key)1 unmodified linereturn response.choices[0].message.contentdef 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].textdef 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 linesdef 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(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)return response.choices[0].message.contentdef 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")14 unmodified linesdef 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.")33 unmodified lineschat_history.append((model, response))except Exception as e:chat_history.append((model, f"Error: {e!s}"))progress(1.0, desc="Done!")return chat_history1 unmodified linewith gr.Blocks() as demo:gr.Markdown("# Model Response Comparison")gr.Markdown("""Select multiple models to compare their responses""")with gr.Row():with gr.Column():
12345678import gradio as grimport ai_gradiodemo = gr.load(name='crewai:gpt-4-turbo',crew_type='article', # or 'support'src=ai_gradio.registry,)12345678import ai_gradioimport gradio as grdemo = gr.load(name="crewai:gpt-4-turbo",crew_type="article", # or 'support'src=ai_gradio.registry,)
1234567import gradio as grimport ai_gradiodemo = gr.load(name='deepseek:deepseek-chat',src=ai_gradio.registry,)1234567import ai_gradioimport gradio as grdemo = gr.load(name="deepseek:deepseek-chat",src=ai_gradio.registry,)
12345624 unmodified lines3132333435363738399 unmodified lines495051525354559 unmodified lines656667686970711 unmodified line73747576777879808182838485869 unmodified lines969798991001011022 unmodified lines10510610710810911011111211311411511611714 unmodified lines132133134135136137138107 unmodified lines246247248249250251252import osimport randomfrom typing import Dict, Listimport google.generativeai as genaiimport gradio as gr24 unmodified lines]def generate_discussion_prompt(original_question: str, previous_responses: List[str]) -> str:"""Generate a prompt for models to discuss and build upon previousresponses."""prompt = f"""You are participating in a multi-AI discussion about this question: "{original_question}"Previous responses from other AI models:9 unmodified linesreturn promptdef 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:import openaiclient = openai.OpenAI(api_key=api_key)1 unmodified linereturn response.choices[0].message.contentdef 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].textdef 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 linesdef 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(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)return response.choices[0].message.contentdef 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")14 unmodified linesdef 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.")107 unmodified linesmessages=[{"role": "user", "content": consensus_prompt}], api_key=api_key)except Exception as e:final_consensus = f"Error getting consensus from {model}: {str(e)}"chat_history.append(("Final Consensus", final_consensus))1234524 unmodified lines303132333435363738399 unmodified lines495051525354559 unmodified lines656667686970711 unmodified line73747576777879808182838485869 unmodified lines969798991001011022 unmodified lines10510610710810911011111211311411511611711811912014 unmodified lines135136137138139140141107 unmodified lines249250251252253254255import osimport randomimport google.generativeai as genaiimport gradio as gr24 unmodified lines]def generate_discussion_prompt(original_question: str, previous_responses: list[str]) -> str:"""Generate a prompt for models to discuss and build upon previousresponses."""prompt = f"""You are participating in a multi-AI discussion about this question: "{original_question}"Previous responses from other AI models:9 unmodified linesreturn promptdef 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:import openaiclient = openai.OpenAI(api_key=api_key)1 unmodified linereturn response.choices[0].message.contentdef 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].textdef 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 linesdef 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(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)return response.choices[0].message.contentdef 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")14 unmodified linesdef 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.")107 unmodified linesmessages=[{"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))
12345678910111213141516171819201 unmodified line22232425262728import osimport ai_gradiofrom 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,1 unmodified linesrc=ai_gradio.registry,dropdown_label="Select Groq Model",choices=GROQ_MODELS_DISPLAY,fill_height=True)if __name__ == "__main__":1234567891011121 unmodified line14151617181920import ai_gradiofrom 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,1 unmodified linesrc=ai_gradio.registry,dropdown_label="Select Groq Model",choices=GROQ_MODELS_DISPLAY,fill_height=True,)if __name__ == "__main__":
12345678910111213141516172 unmodified lines20212223242526import ai_gradiofrom 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(2 unmodified linesdropdown_label="Select Groq Model",choices=GROQ_MODELS_DISPLAY, # Display names without prefixfill_height=True,coder=True)1234567891011122 unmodified lines15161718192021import ai_gradiofrom 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(2 unmodified linesdropdown_label="Select Groq Model",choices=GROQ_MODELS_DISPLAY, # Display names without prefixfill_height=True,coder=True,)
43 unmodified lines44454647484950515253545543 unmodified linestry: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)}"with gr.Blocks() as demo:client = gr.State()model_dropdown = gr.Dropdown(43 unmodified lines444546474849505152535443 unmodified linestry:return create_chat_fn(client)(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()model_dropdown = gr.Dropdown(
12345678910111213141516172 unmodified lines202122232425import ai_gradiofrom 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 utility2 unmodified linesdefault_model=HYPERBOLIC_MODELS_FULL[-1],dropdown_label="Select Hyperbolic Model",choices=HYPERBOLIC_MODELS_DISPLAY, # Display names without prefixfill_height=True)1234567891011122 unmodified lines1516171819import ai_gradiofrom 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 utility2 unmodified linesdefault_model=HYPERBOLIC_MODELS_FULL[-1],dropdown_label="Select Hyperbolic Model",choices=HYPERBOLIC_MODELS_DISPLAY, # Display names without prefixfill_height=True,)
12345678910111213141516173 unmodified lines212223242526import ai_gradiofrom 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 utility3 unmodified linesdropdown_label="Select Hyperbolic Model",choices=HYPERBOLIC_MODELS_DISPLAY, # Display names without prefixfill_height=True,coder=True)1234567891011123 unmodified lines1617181920import ai_gradiofrom 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 utility3 unmodified linesdropdown_label="Select Hyperbolic Model",choices=HYPERBOLIC_MODELS_DISPLAY, # Display names without prefixfill_height=True,coder=True,)
123456789101112131415161718import ai_gradiofrom 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(123456789101112import ai_gradiofrom 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(
123456789101112131415161718import ai_gradiofrom 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(123456789101112import ai_gradiofrom 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(
42 unmodified lines434445464748495042 unmodified linesmessage, history)except Exception as e:print(f"Error during chat: {str(e)}")return f"Error during chat: {str(e)}"with gr.Blocks() as demo:42 unmodified lines434445464748495042 unmodified linesmessage, history)except Exception as e:print(f"Error during chat: {e!s}")return f"Error during chat: {e!s}"with gr.Blocks() as demo:
12345678910111213141516import ai_gradiofrom utils_ai_gradio import get_appSMOLAGENTS_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]demo = get_app(models=SMOLAGENTS_MODELS_FULL, # Use the full names with prefix1234567891011import ai_gradiofrom utils_ai_gradio import get_appSMOLAGENTS_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]demo = get_app(models=SMOLAGENTS_MODELS_FULL, # Use the full names with prefix
1234567892 unmodified lines12131415161718import gradio as grdemo = gr.load(name='akhaliq/phi-4',src="spaces")# Disable API access for all functionsif hasattr(demo, "fns"):2 unmodified linesif __name__ == "__main__":demo.launch()1234562 unmodified lines91011import gradio as grdemo = gr.load(name="akhaliq/phi-4", src="spaces")# Disable API access for all functionsif hasattr(demo, "fns"):2 unmodified linesif __name__ == "__main__":demo.launch()
58 unmodified lines59606162636458 unmodified lines[tool.ruff.lint]select = ["E", "F", "I", "N", "S", "T", "UP", "W"][tool.ruff.format]docstring-code-format = true58 unmodified lines5960616263646558 unmodified lines[tool.ruff.lint]select = ["E", "F", "I", "N", "S", "T", "UP", "W"]ignore = ["T201"][tool.ruff.format]docstring-code-format = true
12341 unmodified line678910111224 unmodified lines37383940from typing import Callable, Dict, Literal, Unionimport gradio as gr1 unmodified linedef get_app(models: list[str],default_model: str,src: Union[Callable[[str, str | None], gr.Blocks], Literal["models"], Dict[str, gr.Blocks]],accept_token: bool = False,dropdown_label: str = "Select Model",**kwargs,24 unmodified linesfor fn in demo.fns.values():fn.api_name = Falsereturn demo123451 unmodified line7891011121324 unmodified lines38394041from collections.abc import Callablefrom typing import Literalimport gradio as gr1 unmodified linedef get_app(models: list[str],default_model: str,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 linesfor fn in demo.fns.values():fn.api_name = Falsereturn demo
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