Spaces:
Sleeping
Sleeping
Add top-tier models: Llama, Qwen, DeepSeek, Mistral, Gemma
Browse files
app.py
CHANGED
|
@@ -1,100 +1,109 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
from huggingface_hub import InferenceClient
|
| 3 |
-
import os
|
| 4 |
|
| 5 |
-
#
|
| 6 |
-
client = InferenceClient(token=os.environ.get("HF_TOKEN"))
|
| 7 |
-
|
| 8 |
-
# List of available models (you can add more)
|
| 9 |
AVAILABLE_MODELS = [
|
| 10 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 11 |
"Qwen/Qwen2.5-Coder-32B-Instruct",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 12 |
"mistralai/Mistral-7B-Instruct-v0.3",
|
| 13 |
-
|
|
|
|
| 14 |
"microsoft/Phi-3.5-mini-instruct",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 15 |
"HuggingFaceH4/zephyr-7b-beta",
|
| 16 |
-
"tiiuae/falcon-7b-instruct",
|
| 17 |
"NousResearch/Nous-Hermes-2-Mixtral-8x7B-DPO",
|
| 18 |
]
|
| 19 |
|
| 20 |
def chat_with_models(message, history, selected_models):
|
| 21 |
-
"""
|
| 22 |
-
Send message to selected models and return their responses
|
| 23 |
-
"""
|
| 24 |
if not selected_models:
|
| 25 |
-
return history + [(message, "β οΈ Please select at least one model
|
| 26 |
-
|
| 27 |
if len(selected_models) > 5:
|
| 28 |
-
return history + [(message, "β οΈ
|
| 29 |
|
| 30 |
-
# Create response text
|
| 31 |
responses = []
|
| 32 |
-
|
| 33 |
for model_name in selected_models:
|
| 34 |
try:
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 42 |
except Exception as e:
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
|
|
|
|
|
|
| 47 |
|
| 48 |
-
|
| 49 |
-
with gr.Blocks(title="Anki-Chat: Multi-Model Chat", theme=gr.themes.Soft()) as demo:
|
| 50 |
gr.Markdown(
|
| 51 |
-
""
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
Select up to 5 AI models and chat with them simultaneously to compare their responses!
|
| 55 |
-
"""
|
| 56 |
)
|
| 57 |
-
|
| 58 |
with gr.Row():
|
| 59 |
with gr.Column(scale=1):
|
| 60 |
gr.Markdown("### Select Models (Max 5)")
|
| 61 |
-
|
| 62 |
choices=AVAILABLE_MODELS,
|
| 63 |
label="Available Models",
|
| 64 |
-
value=[AVAILABLE_MODELS[
|
| 65 |
)
|
| 66 |
-
|
| 67 |
-
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
|
|
|
|
|
|
|
|
|
|
| 71 |
)
|
| 72 |
-
|
|
|
|
| 73 |
with gr.Row():
|
| 74 |
msg = gr.Textbox(
|
| 75 |
-
label="
|
| 76 |
-
placeholder="Type
|
| 77 |
-
scale=4
|
| 78 |
)
|
| 79 |
-
|
| 80 |
-
|
| 81 |
-
clear_btn = gr.Button("Clear Chat")
|
| 82 |
|
| 83 |
-
|
| 84 |
-
msg.submit(chat_with_models, [msg, chatbot, model_checkboxes], [chatbot]).then(
|
| 85 |
lambda: "", None, [msg]
|
| 86 |
)
|
| 87 |
-
|
| 88 |
lambda: "", None, [msg]
|
| 89 |
)
|
| 90 |
-
|
| 91 |
|
| 92 |
gr.Markdown(
|
| 93 |
-
""
|
| 94 |
-
-
|
| 95 |
-
**Note:** This app uses Hugging Face's Inference API. Some models may take longer to respond or may be rate-limited.
|
| 96 |
-
"""
|
| 97 |
)
|
| 98 |
|
| 99 |
-
|
| 100 |
-
demo.launch()
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
from huggingface_hub import InferenceClient
|
|
|
|
| 3 |
|
| 4 |
+
# List of top-tier models from various providers available on Hugging Face
|
|
|
|
|
|
|
|
|
|
| 5 |
AVAILABLE_MODELS = [
|
| 6 |
+
# Meta Llama models
|
| 7 |
+
"meta-llama/Meta-Llama-3.1-70B-Instruct",
|
| 8 |
+
"meta-llama/Meta-Llama-3.1-8B-Instruct",
|
| 9 |
+
|
| 10 |
+
# Qwen models (Alibaba)
|
| 11 |
+
"Qwen/Qwen2.5-72B-Instruct",
|
| 12 |
+
"Qwen/Qwen2.5-7B-Instruct",
|
| 13 |
"Qwen/Qwen2.5-Coder-32B-Instruct",
|
| 14 |
+
|
| 15 |
+
# DeepSeek models
|
| 16 |
+
"deepseek-ai/DeepSeek-V3",
|
| 17 |
+
"deepseek-ai/DeepSeek-R1-Distill-Qwen-32B",
|
| 18 |
+
|
| 19 |
+
# Mistral models
|
| 20 |
+
"mistralai/Mixtral-8x7B-Instruct-v0.1",
|
| 21 |
"mistralai/Mistral-7B-Instruct-v0.3",
|
| 22 |
+
|
| 23 |
+
# Microsoft models
|
| 24 |
"microsoft/Phi-3.5-mini-instruct",
|
| 25 |
+
|
| 26 |
+
# Google models
|
| 27 |
+
"google/gemma-2-27b-it",
|
| 28 |
+
"google/gemma-2-9b-it",
|
| 29 |
+
|
| 30 |
+
# Other top models
|
| 31 |
"HuggingFaceH4/zephyr-7b-beta",
|
|
|
|
| 32 |
"NousResearch/Nous-Hermes-2-Mixtral-8x7B-DPO",
|
| 33 |
]
|
| 34 |
|
| 35 |
def chat_with_models(message, history, selected_models):
|
|
|
|
|
|
|
|
|
|
| 36 |
if not selected_models:
|
| 37 |
+
return history + [(message, "β οΈ Please select at least one model!")]
|
|
|
|
| 38 |
if len(selected_models) > 5:
|
| 39 |
+
return history + [(message, "β οΈ Maximum 5 models allowed!")]
|
| 40 |
|
|
|
|
| 41 |
responses = []
|
|
|
|
| 42 |
for model_name in selected_models:
|
| 43 |
try:
|
| 44 |
+
client = InferenceClient(model=model_name)
|
| 45 |
+
try:
|
| 46 |
+
result = client.chat_completion(
|
| 47 |
+
messages=[{"role": "user", "content": message}],
|
| 48 |
+
max_tokens=500
|
| 49 |
+
)
|
| 50 |
+
response = result.choices[0].message.content
|
| 51 |
+
except:
|
| 52 |
+
result = client.text_generation(message, max_new_tokens=300)
|
| 53 |
+
response = result
|
| 54 |
+
responses.append(f"**{model_name}:**\n{response}\n")
|
| 55 |
except Exception as e:
|
| 56 |
+
error = str(e)
|
| 57 |
+
if "loading" in error.lower():
|
| 58 |
+
responses.append(f"**{model_name}:**\nβ³ Loading...\n")
|
| 59 |
+
else:
|
| 60 |
+
responses.append(f"**{model_name}:**\nβ {error[:100]}\n")
|
| 61 |
+
return history + [(message, "\n---\n\n".join(responses))]
|
| 62 |
|
| 63 |
+
with gr.Blocks(title="Anki-Chat", theme=gr.themes.Soft()) as demo:
|
|
|
|
| 64 |
gr.Markdown(
|
| 65 |
+
"# π€ Anki-Chat: Multi-Model Comparison\n"
|
| 66 |
+
"Chat with top AI models: Meta Llama, Qwen, DeepSeek, Mistral, Google & more!"
|
|
|
|
|
|
|
|
|
|
| 67 |
)
|
|
|
|
| 68 |
with gr.Row():
|
| 69 |
with gr.Column(scale=1):
|
| 70 |
gr.Markdown("### Select Models (Max 5)")
|
| 71 |
+
checkboxes = gr.CheckboxGroup(
|
| 72 |
choices=AVAILABLE_MODELS,
|
| 73 |
label="Available Models",
|
| 74 |
+
value=[AVAILABLE_MODELS[1]]
|
| 75 |
)
|
| 76 |
+
gr.Markdown(
|
| 77 |
+
"**Providers:**\n"
|
| 78 |
+
"- π¦ Meta Llama 3.1\n"
|
| 79 |
+
"- π Qwen 2.5 (Alibaba)\n"
|
| 80 |
+
"- π¦ DeepSeek V3 & R1\n"
|
| 81 |
+
"- β¨ Mistral\n"
|
| 82 |
+
"- π Google Gemma\n"
|
| 83 |
+
"- π₯ Microsoft Phi"
|
| 84 |
)
|
| 85 |
+
with gr.Column(scale=2):
|
| 86 |
+
chatbot = gr.Chatbot(label="Chat", height=500)
|
| 87 |
with gr.Row():
|
| 88 |
msg = gr.Textbox(
|
| 89 |
+
label="Message",
|
| 90 |
+
placeholder="Type here...",
|
| 91 |
+
scale=4
|
| 92 |
)
|
| 93 |
+
send = gr.Button("Send", scale=1, variant="primary")
|
| 94 |
+
clear = gr.Button("Clear")
|
|
|
|
| 95 |
|
| 96 |
+
msg.submit(chat_with_models, [msg, chatbot, checkboxes], [chatbot]).then(
|
|
|
|
| 97 |
lambda: "", None, [msg]
|
| 98 |
)
|
| 99 |
+
send.click(chat_with_models, [msg, chatbot, checkboxes], [chatbot]).then(
|
| 100 |
lambda: "", None, [msg]
|
| 101 |
)
|
| 102 |
+
clear.click(lambda: [], None, [chatbot])
|
| 103 |
|
| 104 |
gr.Markdown(
|
| 105 |
+
"**Note:** Using HF Serverless Inference API. "
|
| 106 |
+
"Large models may take 20-30s to load initially."
|
|
|
|
|
|
|
| 107 |
)
|
| 108 |
|
| 109 |
+
demo.launch()
|
|
|