Nick088 commited on
Commit
110c323
1 Parent(s): e42b84a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +21 -18
app.py CHANGED
@@ -1,23 +1,22 @@
1
- import subprocess
2
  import os
3
  import gradio as gr
4
  from groq import Groq
5
 
6
- def generate_response(input_text):
7
- client = Groq(
8
- api_key=os.environ.get("Groq_Api_Key"),
9
- )
10
 
 
 
11
 
12
  stream = client.chat.completions.create(
13
  messages=[
14
  {"role": "system", "content": "you are a helpful assistant."},
15
  {"role": "user", "content": input_text}
16
  ],
17
- model="mixtral-8x7b-32768",
18
- temperature=0.5,
19
- max_tokens=1024,
20
- top_p=1,
21
  stop=None,
22
  stream=True,
23
  )
@@ -30,14 +29,18 @@ def generate_response(input_text):
30
 
31
  return response
32
 
33
- # Define the Gradio UI
34
- inputs = gr.Textbox(label="Enter your question")
35
- outputs = gr.Textbox(label="Model Response")
 
 
 
 
36
 
37
- gr.Interface(
38
  fn=generate_response,
39
- inputs=inputs,
40
- outputs=outputs,
41
- title="Language Model Assistant",
42
- description="Ask questions and get responses from a language model.",
43
- ).launch(show_api=False, share=True)
 
 
1
  import os
2
  import gradio as gr
3
  from groq import Groq
4
 
5
+ import gradio as gr
6
+ from groq import Groq
 
 
7
 
8
+ def generate_response(input_text, model, temperature, max_tokens, top_p):
9
+ client = Groq()
10
 
11
  stream = client.chat.completions.create(
12
  messages=[
13
  {"role": "system", "content": "you are a helpful assistant."},
14
  {"role": "user", "content": input_text}
15
  ],
16
+ model=model,
17
+ temperature=temperature,
18
+ max_tokens=max_tokens,
19
+ top_p=top_p,
20
  stop=None,
21
  stream=True,
22
  )
 
29
 
30
  return response
31
 
32
+ # Define the Gradio chat interface
33
+ additional_inputs = [
34
+ gr.Dropdown(choices=["mixtral-8x7b-32768", "mixtral-12x7b-32768"], label="Model"),
35
+ gr.Slider(minimum=0.0, maximum=1.0, step=0.01, label="Temperature"),
36
+ gr.Slider(minimum=1, maximum=4096, step=1, label="Max Tokens"),
37
+ gr.Slider(minimum=0.0, maximum=1.0, step=0.01, label="Top P"),
38
+ ]
39
 
40
+ gr.ChatInterface(
41
  fn=generate_response,
42
+ chatbot=gr.Chatbot(show_label=False, show_share_button=False, show_copy_button=True, likeable=True, layout="panel"),
43
+ additional_inputs=additional_inputs,
44
+ title="Groq API LLMs AI Models",
45
+ description="Using https://groq.com/ api, ofc as its free it will have some limitations so its better if you duplicate this space with your own api key<br>Hugging Face Space by [Nick088](https://linktr.ee/Nick088",
46
+ ).launch()