Nymbo commited on
Commit
ec21d4f
·
verified ·
1 Parent(s): 216c971

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +50 -13
app.py CHANGED
@@ -3,13 +3,17 @@ import random
3
  import gradio as gr
4
  from groq import Groq
5
 
 
6
  client = Groq(
7
- api_key = os.environ.get("Groq_Api_Key")
8
  )
9
-
10
  def create_history_messages(history):
11
- history_messages = [{"role": "user", "content": m[0]} for m in history]
12
- history_messages.extend([{"role": "assistant", "content": m[1]} for m in history])
 
 
 
13
  return history_messages
14
 
15
  def generate_response(prompt, history, model, temperature, max_tokens, top_p, seed):
@@ -38,18 +42,51 @@ def generate_response(prompt, history, model, temperature, max_tokens, top_p, se
38
  response += delta_content
39
  yield response
40
 
41
- return response
42
-
43
  additional_inputs = [
44
- gr.Dropdown(choices=["llama-3.1-405b-reasoning", "llama-3.1-70b-versatile", "llama-3.1-8b-instant", "llama3-70b-8192", "llama3-8b-8192", "mixtral-8x7b-32768", "gemma2-9b-it", "gemma-7b-it"], value="llama-3.1-70b-versatile", label="Model"),
45
- gr.Slider(minimum=0.0, maximum=1.0, step=0.01, value=0.5, label="Temperature", info="Controls diversity of the generated text. Lower is more deterministic, higher is more creative."),
46
- gr.Slider(minimum=1, maximum=131000, step=1, value=8100, label="Max Tokens", info="The maximum number of tokens that the model can process in a single response.<br>Maximums: 8k for gemma 7b it, gemma2 9b it, llama 7b & 70b, 32k for mixtral 8x7b, 132k for llama 3.1."),
47
- gr.Slider(minimum=0.0, maximum=1.0, step=0.01, value=0.5, label="Top P", info="A method of text generation where a model will only consider the most probable next tokens that make up the probability p."),
48
- gr.Number(precision=0, value=0, label="Seed", info="A starting point to initiate generation, use 0 for random")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
49
  ]
50
 
51
  gr.ChatInterface(
52
- fn=generate_response, theme="Nymbo/Alyx_Theme",
53
- chatbot=gr.Chatbot(show_label=False, show_share_button=False, show_copy_button=True, likeable=True, layout="panel"),
 
 
 
 
 
 
 
54
  additional_inputs=additional_inputs,
55
  ).launch()
 
3
  import gradio as gr
4
  from groq import Groq
5
 
6
+ # Initialize the Groq client with your API key
7
  client = Groq(
8
+ api_key=os.environ.get("Groq_Api_Key")
9
  )
10
+
11
  def create_history_messages(history):
12
+ # Interleave user and assistant messages in the order they occurred
13
+ history_messages = []
14
+ for user_msg, assistant_msg in history:
15
+ history_messages.append({"role": "user", "content": user_msg})
16
+ history_messages.append({"role": "assistant", "content": assistant_msg})
17
  return history_messages
18
 
19
  def generate_response(prompt, history, model, temperature, max_tokens, top_p, seed):
 
42
  response += delta_content
43
  yield response
44
 
 
 
45
  additional_inputs = [
46
+ gr.Dropdown(
47
+ choices=[
48
+ "llama-3.1-405b-reasoning",
49
+ "llama-3.1-70b-versatile",
50
+ "llama-3.1-8b-instant",
51
+ "llama3-70b-8192",
52
+ "llama3-8b-8192",
53
+ "mixtral-8x7b-32768",
54
+ "gemma2-9b-it",
55
+ "gemma-7b-it"
56
+ ],
57
+ value="llama-3.1-70b-versatile",
58
+ label="Model"
59
+ ),
60
+ gr.Slider(
61
+ minimum=0.0, maximum=1.0, step=0.01, value=0.5,
62
+ label="Temperature",
63
+ info="Controls diversity of the generated text. Lower is more deterministic, higher is more creative."
64
+ ),
65
+ gr.Slider(
66
+ minimum=1, maximum=131000, step=1, value=8100,
67
+ label="Max Tokens",
68
+ info="The maximum number of tokens that the model can process in a single response.<br>Maximums: 8k for gemma 7b it, gemma2 9b it, llama 7b & 70b, 32k for mixtral 8x7b, 132k for llama 3.1."
69
+ ),
70
+ gr.Slider(
71
+ minimum=0.0, maximum=1.0, step=0.01, value=0.5,
72
+ label="Top P",
73
+ info="A method of text generation where a model will only consider the most probable next tokens that make up the probability p."
74
+ ),
75
+ gr.Number(
76
+ precision=0, value=0, label="Seed",
77
+ info="A starting point to initiate generation, use 0 for random"
78
+ )
79
  ]
80
 
81
  gr.ChatInterface(
82
+ fn=generate_response,
83
+ theme="Nymbo/Alyx_Theme",
84
+ chatbot=gr.Chatbot(
85
+ show_label=False,
86
+ show_share_button=False,
87
+ show_copy_button=True,
88
+ likeable=True,
89
+ layout="panel"
90
+ ),
91
  additional_inputs=additional_inputs,
92
  ).launch()