Mubbashir Ahmed commited on
Commit
725f763
·
1 Parent(s): 016c388

added mistral model

Browse files
Files changed (1) hide show
  1. app.py +21 -6
app.py CHANGED
@@ -2,17 +2,18 @@ import os
2
  import gradio as gr
3
  from huggingface_hub import InferenceClient
4
 
5
- # Clients for both providers
6
  llama_client = InferenceClient(provider="sambanova", api_key=os.environ["HF_TOKEN"])
7
  minimax_client = InferenceClient(provider="novita", api_key=os.environ["HF_TOKEN"])
 
8
 
9
  def chat_with_model(model_choice, prompt, image_url):
10
  if not prompt:
11
  return "Please enter a text prompt."
12
 
13
  try:
 
14
  if model_choice == "LLaMA 4 (SambaNova)":
15
- # Prepare message with optional image
16
  content = [{"type": "text", "text": prompt}]
17
  if image_url:
18
  content.append({
@@ -27,6 +28,7 @@ def chat_with_model(model_choice, prompt, image_url):
27
  )
28
  return completion.choices[0].message.content
29
 
 
30
  elif model_choice == "MiniMax M1 (Novita)":
31
  messages = [{"role": "user", "content": prompt}]
32
  completion = minimax_client.chat.completions.create(
@@ -35,6 +37,15 @@ def chat_with_model(model_choice, prompt, image_url):
35
  )
36
  return completion.choices[0].message.content
37
 
 
 
 
 
 
 
 
 
 
38
  else:
39
  return "Unsupported model selected."
40
 
@@ -43,17 +54,21 @@ def chat_with_model(model_choice, prompt, image_url):
43
 
44
  # Gradio UI
45
  with gr.Blocks() as demo:
46
- gr.Markdown("## 🤖 Multimodel Chatbot: LLaMA 4 & MiniMax M1")
47
- gr.Markdown("Choose a model, enter your prompt, and optionally add an image URL for LLaMA.")
48
 
49
  model_dropdown = gr.Dropdown(
50
- choices=["LLaMA 4 (SambaNova)", "MiniMax M1 (Novita)"],
 
 
 
 
51
  value="LLaMA 4 (SambaNova)",
52
  label="Select Model"
53
  )
54
  prompt_input = gr.Textbox(label="Text Prompt", placeholder="Ask something...", lines=2)
55
  image_url_input = gr.Textbox(label="Optional Image URL (for LLaMA only)", placeholder="https://example.com/image.jpg")
56
-
57
  submit_btn = gr.Button("Generate Response")
58
  output_box = gr.Textbox(label="Response", lines=8)
59
 
 
2
  import gradio as gr
3
  from huggingface_hub import InferenceClient
4
 
5
+ # Setup clients for each provider
6
  llama_client = InferenceClient(provider="sambanova", api_key=os.environ["HF_TOKEN"])
7
  minimax_client = InferenceClient(provider="novita", api_key=os.environ["HF_TOKEN"])
8
+ mistral_client = InferenceClient(provider="together", api_key=os.environ["HF_TOKEN"])
9
 
10
  def chat_with_model(model_choice, prompt, image_url):
11
  if not prompt:
12
  return "Please enter a text prompt."
13
 
14
  try:
15
+ # LLaMA 4 supports optional image input
16
  if model_choice == "LLaMA 4 (SambaNova)":
 
17
  content = [{"type": "text", "text": prompt}]
18
  if image_url:
19
  content.append({
 
28
  )
29
  return completion.choices[0].message.content
30
 
31
+ # MiniMax: Text only
32
  elif model_choice == "MiniMax M1 (Novita)":
33
  messages = [{"role": "user", "content": prompt}]
34
  completion = minimax_client.chat.completions.create(
 
37
  )
38
  return completion.choices[0].message.content
39
 
40
+ # Mistral: Text only
41
+ elif model_choice == "Mistral Mixtral-8x7B (Together)":
42
+ messages = [{"role": "user", "content": prompt}]
43
+ completion = mistral_client.chat.completions.create(
44
+ model="mistralai/Mixtral-8x7B-Instruct-v0.1",
45
+ messages=messages
46
+ )
47
+ return completion.choices[0].message.content
48
+
49
  else:
50
  return "Unsupported model selected."
51
 
 
54
 
55
  # Gradio UI
56
  with gr.Blocks() as demo:
57
+ gr.Markdown("## 🤖 Unified Chatbot Interface")
58
+ gr.Markdown("Supports LLaMA 4 (with optional image), MiniMax, and Mistral.")
59
 
60
  model_dropdown = gr.Dropdown(
61
+ choices=[
62
+ "LLaMA 4 (SambaNova)",
63
+ "MiniMax M1 (Novita)",
64
+ "Mistral Mixtral-8x7B (Together)"
65
+ ],
66
  value="LLaMA 4 (SambaNova)",
67
  label="Select Model"
68
  )
69
  prompt_input = gr.Textbox(label="Text Prompt", placeholder="Ask something...", lines=2)
70
  image_url_input = gr.Textbox(label="Optional Image URL (for LLaMA only)", placeholder="https://example.com/image.jpg")
71
+
72
  submit_btn = gr.Button("Generate Response")
73
  output_box = gr.Textbox(label="Response", lines=8)
74