Update app.py
Browse files
app.py
CHANGED
@@ -277,25 +277,31 @@ HUGGINGFACE_MODELS = {
|
|
277 |
|
278 |
# GROQ MODELS - We'll populate this dynamically
|
279 |
DEFAULT_GROQ_MODELS = {
|
|
|
|
|
280 |
"gemma2-9b-it": 8192,
|
281 |
-
"gemma-7b-it": 8192,
|
282 |
-
"llama-3.3-70b-versatile": 131072,
|
283 |
-
"llama-3.1-70b-versatile": 131072,
|
284 |
"llama-3.1-8b-instant": 131072,
|
285 |
-
"llama-guard-3-8b": 8192,
|
286 |
-
"llama3-70b-8192": 8192,
|
287 |
-
"llama3-8b-8192": 8192,
|
288 |
-
"mixtral-8x7b-32768": 32768,
|
289 |
-
"llama3-groq-70b-8192-tool-use-preview": 8192,
|
290 |
-
"llama3-groq-8b-8192-tool-use-preview": 8192,
|
291 |
-
"llama-3.3-70b-specdec": 131072,
|
292 |
-
"llama-3.1-70b-specdec": 131072,
|
293 |
"llama-3.2-1b-preview": 131072,
|
294 |
"llama-3.2-3b-preview": 131072,
|
295 |
-
"llama-3.2-11b-vision": 131072,
|
296 |
-
"llama-3.2-90b-vision": 131072,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
297 |
}
|
298 |
|
|
|
299 |
# COHERE MODELS
|
300 |
COHERE_MODELS = {
|
301 |
"command-r-plus-08-2024": 131072,
|
@@ -673,7 +679,7 @@ def call_openrouter_api(payload, api_key_override=None):
|
|
673 |
headers={
|
674 |
"Content-Type": "application/json",
|
675 |
"Authorization": f"Bearer {api_key}",
|
676 |
-
"HTTP-Referer": "https://huggingface.co/spaces/
|
677 |
},
|
678 |
json=payload,
|
679 |
timeout=180 # Longer timeout for document processing
|
@@ -1669,9 +1675,9 @@ def clear_chat():
|
|
1669 |
# ==========================================================
|
1670 |
|
1671 |
def create_app():
|
1672 |
-
"""Create the
|
1673 |
with gr.Blocks(
|
1674 |
-
title="
|
1675 |
css="""
|
1676 |
.context-size {
|
1677 |
font-size: 0.9em;
|
@@ -1705,7 +1711,7 @@ def create_app():
|
|
1705 |
"""
|
1706 |
) as demo:
|
1707 |
gr.Markdown("""
|
1708 |
-
# 🤖
|
1709 |
|
1710 |
Chat with AI models from multiple providers: OpenRouter, OpenAI, HuggingFace, Groq, Cohere, Together, OVH, Cerebras, and Google AI.
|
1711 |
""")
|
@@ -1762,6 +1768,7 @@ def create_app():
|
|
1762 |
)
|
1763 |
|
1764 |
with gr.Column(scale=1):
|
|
|
1765 |
with gr.Group(elem_classes="provider-selection"):
|
1766 |
gr.Markdown("### Provider Selection")
|
1767 |
|
@@ -1772,12 +1779,58 @@ def create_app():
|
|
1772 |
label="AI Provider"
|
1773 |
)
|
1774 |
|
1775 |
-
# API key input
|
1776 |
-
|
1777 |
-
|
1778 |
-
|
1779 |
-
|
1780 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1781 |
|
1782 |
with gr.Group():
|
1783 |
gr.Markdown("### Model Selection")
|
@@ -2040,7 +2093,7 @@ def create_app():
|
|
2040 |
# Add a footer with version info
|
2041 |
footer_md = gr.Markdown("""
|
2042 |
---
|
2043 |
-
###
|
2044 |
Built with ❤️ using Gradio and multiple AI provider APIs | Context sizes shown next to model names
|
2045 |
""")
|
2046 |
|
@@ -2504,20 +2557,40 @@ def create_app():
|
|
2504 |
)
|
2505 |
|
2506 |
# Set up submission event
|
2507 |
-
def submit_message(message, history, provider, openrouter_model, openai_model, hf_model, groq_model, cohere_model,
|
2508 |
-
|
2509 |
-
|
2510 |
-
|
|
|
|
|
2511 |
"""Submit message to selected provider and model"""
|
2512 |
# Get the currently selected model
|
2513 |
-
model_choice = get_current_model(provider, openrouter_model, openai_model, hf_model, groq_model, cohere_model,
|
|
|
2514 |
|
2515 |
# Check if model is selected
|
2516 |
if not model_choice:
|
2517 |
new_history = history.copy()
|
2518 |
new_history.append([message, f"Error: No model selected for provider {provider}"])
|
2519 |
return new_history
|
2520 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2521 |
# Call the ask_ai function with the appropriate parameters
|
2522 |
return ask_ai(
|
2523 |
message=message,
|
@@ -2552,7 +2625,8 @@ def create_app():
|
|
2552 |
openrouter_model, openai_model, hf_model, groq_model, cohere_model, together_model, ovh_model, cerebras_model, googleai_model,
|
2553 |
temperature, max_tokens, top_p, frequency_penalty, presence_penalty, repetition_penalty,
|
2554 |
top_k, min_p, seed, top_a, stream_output, response_format,
|
2555 |
-
images, documents, reasoning_effort, system_message, transforms,
|
|
|
2556 |
],
|
2557 |
outputs=chatbot,
|
2558 |
show_progress="minimal",
|
@@ -2570,7 +2644,8 @@ def create_app():
|
|
2570 |
openrouter_model, openai_model, hf_model, groq_model, cohere_model, together_model, ovh_model, cerebras_model, googleai_model,
|
2571 |
temperature, max_tokens, top_p, frequency_penalty, presence_penalty, repetition_penalty,
|
2572 |
top_k, min_p, seed, top_a, stream_output, response_format,
|
2573 |
-
images, documents, reasoning_effort, system_message, transforms,
|
|
|
2574 |
],
|
2575 |
outputs=chatbot,
|
2576 |
show_progress="minimal",
|
@@ -2636,7 +2711,7 @@ if __name__ == "__main__":
|
|
2636 |
if "OVH" not in missing_keys and "Cerebras" not in missing_keys:
|
2637 |
print("\nNote: OVH AI Endpoints (beta) and Cerebras offer free usage tiers!")
|
2638 |
|
2639 |
-
print("\nStarting
|
2640 |
demo = create_app()
|
2641 |
demo.launch(
|
2642 |
server_name="0.0.0.0",
|
|
|
277 |
|
278 |
# GROQ MODELS - We'll populate this dynamically
|
279 |
DEFAULT_GROQ_MODELS = {
|
280 |
+
"deepseek-r1-distill-llama-70b": 8192,
|
281 |
+
"deepseek-r1-distill-qwen-32b": 8192,
|
282 |
"gemma2-9b-it": 8192,
|
|
|
|
|
|
|
283 |
"llama-3.1-8b-instant": 131072,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
284 |
"llama-3.2-1b-preview": 131072,
|
285 |
"llama-3.2-3b-preview": 131072,
|
286 |
+
"llama-3.2-11b-vision-preview": 131072,
|
287 |
+
"llama-3.2-90b-vision-preview": 131072,
|
288 |
+
"llama-3.3-70b-specdec": 131072,
|
289 |
+
"llama-3.3-70b-versatile": 131072,
|
290 |
+
"llama-guard-3-8b": 8192,
|
291 |
+
"llama3-8b-8192": 8192,
|
292 |
+
"llama3-70b-8192": 8192,
|
293 |
+
"mistral-saba-24b": 32768,
|
294 |
+
"qwen-2.5-32b": 32768,
|
295 |
+
"qwen-2.5-coder-32b": 32768,
|
296 |
+
"qwen-qwq-32b": 32768,
|
297 |
+
"playai-tts": 4096, # Including TTS models but setting reasonable context limits
|
298 |
+
"playai-tts-arabic": 4096,
|
299 |
+
"distil-whisper-large-v3-en": 4096,
|
300 |
+
"whisper-large-v3": 4096,
|
301 |
+
"whisper-large-v3-turbo": 4096
|
302 |
}
|
303 |
|
304 |
+
|
305 |
# COHERE MODELS
|
306 |
COHERE_MODELS = {
|
307 |
"command-r-plus-08-2024": 131072,
|
|
|
679 |
headers={
|
680 |
"Content-Type": "application/json",
|
681 |
"Authorization": f"Bearer {api_key}",
|
682 |
+
"HTTP-Referer": "https://huggingface.co/spaces/cstr/CrispChat"
|
683 |
},
|
684 |
json=payload,
|
685 |
timeout=180 # Longer timeout for document processing
|
|
|
1675 |
# ==========================================================
|
1676 |
|
1677 |
def create_app():
|
1678 |
+
"""Create the CrispChat Gradio application"""
|
1679 |
with gr.Blocks(
|
1680 |
+
title="CrispChat",
|
1681 |
css="""
|
1682 |
.context-size {
|
1683 |
font-size: 0.9em;
|
|
|
1711 |
"""
|
1712 |
) as demo:
|
1713 |
gr.Markdown("""
|
1714 |
+
# 🤖 CrispChat
|
1715 |
|
1716 |
Chat with AI models from multiple providers: OpenRouter, OpenAI, HuggingFace, Groq, Cohere, Together, OVH, Cerebras, and Google AI.
|
1717 |
""")
|
|
|
1768 |
)
|
1769 |
|
1770 |
with gr.Column(scale=1):
|
1771 |
+
|
1772 |
with gr.Group(elem_classes="provider-selection"):
|
1773 |
gr.Markdown("### Provider Selection")
|
1774 |
|
|
|
1779 |
label="AI Provider"
|
1780 |
)
|
1781 |
|
1782 |
+
# API key input with separate fields for each provider
|
1783 |
+
with gr.Accordion("API Keys", open=False):
|
1784 |
+
gr.Markdown("Enter API keys directly or set them as environment variables")
|
1785 |
+
|
1786 |
+
openrouter_api_key = gr.Textbox(
|
1787 |
+
placeholder="Enter OpenRouter API key",
|
1788 |
+
label="OpenRouter API Key",
|
1789 |
+
type="password",
|
1790 |
+
value=OPENROUTER_API_KEY if OPENROUTER_API_KEY else ""
|
1791 |
+
)
|
1792 |
+
|
1793 |
+
openai_api_key = gr.Textbox(
|
1794 |
+
placeholder="Enter OpenAI API key",
|
1795 |
+
label="OpenAI API Key",
|
1796 |
+
type="password",
|
1797 |
+
value=OPENAI_API_KEY if OPENAI_API_KEY else ""
|
1798 |
+
)
|
1799 |
+
|
1800 |
+
hf_api_key = gr.Textbox(
|
1801 |
+
placeholder="Enter HuggingFace API key",
|
1802 |
+
label="HuggingFace API Key",
|
1803 |
+
type="password",
|
1804 |
+
value=HF_API_KEY if HF_API_KEY else ""
|
1805 |
+
)
|
1806 |
+
|
1807 |
+
groq_api_key = gr.Textbox(
|
1808 |
+
placeholder="Enter Groq API key",
|
1809 |
+
label="Groq API Key",
|
1810 |
+
type="password",
|
1811 |
+
value=GROQ_API_KEY if GROQ_API_KEY else ""
|
1812 |
+
)
|
1813 |
+
|
1814 |
+
cohere_api_key = gr.Textbox(
|
1815 |
+
placeholder="Enter Cohere API key",
|
1816 |
+
label="Cohere API Key",
|
1817 |
+
type="password",
|
1818 |
+
value=COHERE_API_KEY if COHERE_API_KEY else ""
|
1819 |
+
)
|
1820 |
+
|
1821 |
+
together_api_key = gr.Textbox(
|
1822 |
+
placeholder="Enter Together API key",
|
1823 |
+
label="Together API Key",
|
1824 |
+
type="password",
|
1825 |
+
value=TOGETHER_API_KEY if TOGETHER_API_KEY else ""
|
1826 |
+
)
|
1827 |
+
|
1828 |
+
googleai_api_key = gr.Textbox(
|
1829 |
+
placeholder="Enter Google AI API key",
|
1830 |
+
label="Google AI API Key",
|
1831 |
+
type="password",
|
1832 |
+
value=GOOGLEAI_API_KEY if GOOGLEAI_API_KEY else ""
|
1833 |
+
)
|
1834 |
|
1835 |
with gr.Group():
|
1836 |
gr.Markdown("### Model Selection")
|
|
|
2093 |
# Add a footer with version info
|
2094 |
footer_md = gr.Markdown("""
|
2095 |
---
|
2096 |
+
### CrispChat v1.1
|
2097 |
Built with ❤️ using Gradio and multiple AI provider APIs | Context sizes shown next to model names
|
2098 |
""")
|
2099 |
|
|
|
2557 |
)
|
2558 |
|
2559 |
# Set up submission event
|
2560 |
+
def submit_message(message, history, provider, openrouter_model, openai_model, hf_model, groq_model, cohere_model,
|
2561 |
+
together_model, ovh_model, cerebras_model, googleai_model,
|
2562 |
+
temperature, max_tokens, top_p, frequency_penalty, presence_penalty, repetition_penalty,
|
2563 |
+
top_k, min_p, seed, top_a, stream_output, response_format,
|
2564 |
+
images, documents, reasoning_effort, system_message, transforms,
|
2565 |
+
openrouter_api_key, openai_api_key, hf_api_key, groq_api_key, cohere_api_key, together_api_key, googleai_api_key):
|
2566 |
"""Submit message to selected provider and model"""
|
2567 |
# Get the currently selected model
|
2568 |
+
model_choice = get_current_model(provider, openrouter_model, openai_model, hf_model, groq_model, cohere_model,
|
2569 |
+
together_model, ovh_model, cerebras_model, googleai_model)
|
2570 |
|
2571 |
# Check if model is selected
|
2572 |
if not model_choice:
|
2573 |
new_history = history.copy()
|
2574 |
new_history.append([message, f"Error: No model selected for provider {provider}"])
|
2575 |
return new_history
|
2576 |
+
|
2577 |
+
# Select the appropriate API key based on the provider
|
2578 |
+
api_key_override = None
|
2579 |
+
if provider == "OpenRouter" and openrouter_api_key:
|
2580 |
+
api_key_override = openrouter_api_key
|
2581 |
+
elif provider == "OpenAI" and openai_api_key:
|
2582 |
+
api_key_override = openai_api_key
|
2583 |
+
elif provider == "HuggingFace" and hf_api_key:
|
2584 |
+
api_key_override = hf_api_key
|
2585 |
+
elif provider == "Groq" and groq_api_key:
|
2586 |
+
api_key_override = groq_api_key
|
2587 |
+
elif provider == "Cohere" and cohere_api_key:
|
2588 |
+
api_key_override = cohere_api_key
|
2589 |
+
elif provider == "Together" and together_api_key:
|
2590 |
+
api_key_override = together_api_key
|
2591 |
+
elif provider == "GoogleAI" and googleai_api_key:
|
2592 |
+
api_key_override = googleai_api_key
|
2593 |
+
|
2594 |
# Call the ask_ai function with the appropriate parameters
|
2595 |
return ask_ai(
|
2596 |
message=message,
|
|
|
2625 |
openrouter_model, openai_model, hf_model, groq_model, cohere_model, together_model, ovh_model, cerebras_model, googleai_model,
|
2626 |
temperature, max_tokens, top_p, frequency_penalty, presence_penalty, repetition_penalty,
|
2627 |
top_k, min_p, seed, top_a, stream_output, response_format,
|
2628 |
+
images, documents, reasoning_effort, system_message, transforms,
|
2629 |
+
openrouter_api_key, openai_api_key, hf_api_key, groq_api_key, cohere_api_key, together_api_key, googleai_api_key
|
2630 |
],
|
2631 |
outputs=chatbot,
|
2632 |
show_progress="minimal",
|
|
|
2644 |
openrouter_model, openai_model, hf_model, groq_model, cohere_model, together_model, ovh_model, cerebras_model, googleai_model,
|
2645 |
temperature, max_tokens, top_p, frequency_penalty, presence_penalty, repetition_penalty,
|
2646 |
top_k, min_p, seed, top_a, stream_output, response_format,
|
2647 |
+
images, documents, reasoning_effort, system_message, transforms,
|
2648 |
+
openrouter_api_key, openai_api_key, hf_api_key, groq_api_key, cohere_api_key, together_api_key, googleai_api_key
|
2649 |
],
|
2650 |
outputs=chatbot,
|
2651 |
show_progress="minimal",
|
|
|
2711 |
if "OVH" not in missing_keys and "Cerebras" not in missing_keys:
|
2712 |
print("\nNote: OVH AI Endpoints (beta) and Cerebras offer free usage tiers!")
|
2713 |
|
2714 |
+
print("\nStarting CrispChat application...")
|
2715 |
demo = create_app()
|
2716 |
demo.launch(
|
2717 |
server_name="0.0.0.0",
|