anktechsol commited on
Commit
a8a81a0
Β·
verified Β·
1 Parent(s): bd1ec04

Add top-tier models: Llama, Qwen, DeepSeek, Mistral, Gemma

Browse files
Files changed (1) hide show
  1. app.py +68 -59
app.py CHANGED
@@ -1,100 +1,109 @@
1
  import gradio as gr
2
  from huggingface_hub import InferenceClient
3
- import os
4
 
5
- # Initialize the Inference Client
6
- client = InferenceClient(token=os.environ.get("HF_TOKEN"))
7
-
8
- # List of available models (you can add more)
9
  AVAILABLE_MODELS = [
10
- "meta-llama/Llama-3.3-70B-Instruct",
 
 
 
 
 
 
11
  "Qwen/Qwen2.5-Coder-32B-Instruct",
 
 
 
 
 
 
 
12
  "mistralai/Mistral-7B-Instruct-v0.3",
13
- "google/gemma-2-9b-it",
 
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 first!")]
26
-
27
  if len(selected_models) > 5:
28
- return history + [(message, "⚠️ Please select maximum 5 models only!")]
29
 
30
- # Create response text
31
  responses = []
32
-
33
  for model_name in selected_models:
34
  try:
35
- response = client.chat_completion(
36
- model=model_name,
37
- messages=[{"role": "user", "content": message}],
38
- max_tokens=500,
39
- )
40
- model_response = response.choices[0].message.content
41
- responses.append(f"**{model_name}:**\n{model_response}\n")
 
 
 
 
42
  except Exception as e:
43
- responses.append(f"**{model_name}:**\n❌ Error: {str(e)}\n")
44
-
45
- combined_response = "\n---\n\n".join(responses)
46
- return history + [(message, combined_response)]
 
 
47
 
48
- # Create the Gradio interface
49
- with gr.Blocks(title="Anki-Chat: Multi-Model Chat", theme=gr.themes.Soft()) as demo:
50
  gr.Markdown(
51
- """
52
- # πŸ€– Anki-Chat: Multi-Model Chat Interface
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
- model_checkboxes = gr.CheckboxGroup(
62
  choices=AVAILABLE_MODELS,
63
  label="Available Models",
64
- value=[AVAILABLE_MODELS[0]], # Default to first model
65
  )
66
-
67
- with gr.Column(scale=2):
68
- chatbot = gr.Chatbot(
69
- label="Chat",
70
- height=500,
 
 
 
71
  )
72
-
 
73
  with gr.Row():
74
  msg = gr.Textbox(
75
- label="Your Message",
76
- placeholder="Type your message here...",
77
- scale=4,
78
  )
79
- send_btn = gr.Button("Send", scale=1, variant="primary")
80
-
81
- clear_btn = gr.Button("Clear Chat")
82
 
83
- # Event handlers
84
- msg.submit(chat_with_models, [msg, chatbot, model_checkboxes], [chatbot]).then(
85
  lambda: "", None, [msg]
86
  )
87
- send_btn.click(chat_with_models, [msg, chatbot, model_checkboxes], [chatbot]).then(
88
  lambda: "", None, [msg]
89
  )
90
- clear_btn.click(lambda: [], None, [chatbot])
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
- if __name__ == "__main__":
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()