SkyNetWalker commited on
Commit
fc98e77
·
verified ·
1 Parent(s): caeafc7

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +16 -3
app.py CHANGED
@@ -1,5 +1,6 @@
1
  #refer llama recipes for more info https://github.com/huggingface/huggingface-llama-recipes/blob/main/inference-api.ipynb
2
  #huggingface-llama-recipes : https://github.com/huggingface/huggingface-llama-recipes/tree/main
 
3
  import gradio as gr
4
  from openai import OpenAI
5
  import os
@@ -22,11 +23,13 @@ def respond(
22
  max_tokens,
23
  temperature,
24
  top_p,
 
25
  ):
26
  print(f"Received message: {message}")
27
  print(f"History: {history}")
28
  print(f"System message: {system_message}")
29
  print(f"Max tokens: {max_tokens}, Temperature: {temperature}, Top-P: {top_p}")
 
30
 
31
  messages = [{"role": "system", "content": system_message}]
32
 
@@ -44,7 +47,7 @@ def respond(
44
  print("Sending request to OpenAI API.")
45
 
46
  for message in client.chat.completions.create(
47
- model="PowerInfer/SmallThinker-3B-Preview",
48
  max_tokens=max_tokens,
49
  stream=True,
50
  temperature=temperature,
@@ -62,9 +65,20 @@ chatbot = gr.Chatbot(height=600)
62
 
63
  print("Chatbot interface created.")
64
 
 
 
 
 
 
 
65
  demo = gr.ChatInterface(
66
  respond,
67
  additional_inputs=[
 
 
 
 
 
68
  gr.Textbox(value="", label="System message"),
69
  gr.Slider(minimum=1, maximum=4096, value=1024, step=1, label="Max new tokens"),
70
  gr.Slider(minimum=0.1, maximum=1.0, value=0.3, step=0.1, label="Temperature"),
@@ -75,7 +89,6 @@ demo = gr.ChatInterface(
75
  step=0.05,
76
  label="Top-P",
77
  ),
78
-
79
  ],
80
  fill_height=True,
81
  chatbot=chatbot,
@@ -85,4 +98,4 @@ print("Gradio interface initialized.")
85
 
86
  if __name__ == "__main__":
87
  print("Launching the demo application.")
88
- demo.launch()
 
1
  #refer llama recipes for more info https://github.com/huggingface/huggingface-llama-recipes/blob/main/inference-api.ipynb
2
  #huggingface-llama-recipes : https://github.com/huggingface/huggingface-llama-recipes/tree/main
3
+
4
  import gradio as gr
5
  from openai import OpenAI
6
  import os
 
23
  max_tokens,
24
  temperature,
25
  top_p,
26
+ model_name, # Added a parameter for model selection
27
  ):
28
  print(f"Received message: {message}")
29
  print(f"History: {history}")
30
  print(f"System message: {system_message}")
31
  print(f"Max tokens: {max_tokens}, Temperature: {temperature}, Top-P: {top_p}")
32
+ print(f"Selected model: {model_name}")
33
 
34
  messages = [{"role": "system", "content": system_message}]
35
 
 
47
  print("Sending request to OpenAI API.")
48
 
49
  for message in client.chat.completions.create(
50
+ model=model_name, # Use the selected model here
51
  max_tokens=max_tokens,
52
  stream=True,
53
  temperature=temperature,
 
65
 
66
  print("Chatbot interface created.")
67
 
68
+ # Define a list of models for the dropdown
69
+ model_options = [
70
+ "microsoft/phi-4",
71
+ "PowerInfer/SmallThinker-3B-Preview",
72
+ ]
73
+
74
  demo = gr.ChatInterface(
75
  respond,
76
  additional_inputs=[
77
+ gr.Dropdown(
78
+ choices=model_options,
79
+ value="microsoft/phi-4",
80
+ label="Select Model",
81
+ ),
82
  gr.Textbox(value="", label="System message"),
83
  gr.Slider(minimum=1, maximum=4096, value=1024, step=1, label="Max new tokens"),
84
  gr.Slider(minimum=0.1, maximum=1.0, value=0.3, step=0.1, label="Temperature"),
 
89
  step=0.05,
90
  label="Top-P",
91
  ),
 
92
  ],
93
  fill_height=True,
94
  chatbot=chatbot,
 
98
 
99
  if __name__ == "__main__":
100
  print("Launching the demo application.")
101
+ demo.launch()