adriiita commited on
Commit
b18dd15
·
verified ·
1 Parent(s): 1143746

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +19 -23
app.py CHANGED
@@ -2,39 +2,35 @@ import os
2
  import gradio as gr
3
  from groq import Groq
4
 
 
5
  client = Groq(
6
  api_key=os.environ.get("GROQ_API_KEY"),
7
  )
8
 
 
 
9
  def chat_with_groq(user_input, additional_context=None):
10
  chat_completion = client.chat.completions.create(
11
- messages=[
12
- {
13
- "role": "user",
14
- "content": user_input,
15
- }
16
- ],
17
- model="llama-3.1-8b-instant",
18
- )
19
  return chat_completion.choices[0].message.content
20
 
21
- with gr.Blocks() as demo:
22
- chatbot = gr.Chatbot()
23
- msg = gr.Textbox(placeholder="Ask me any question", scale=6)
24
- clear = gr.Button("Clear")
25
 
26
- def user_interaction(user_input, history):
27
- response = chat_with_groq(user_input)
28
- history = history + [(user_input, response)]
29
- return history, ""
30
 
31
- msg.submit(user_interaction, [msg, chatbot], [chatbot, msg])
32
- clear.click(lambda: None, None, chatbot)
33
 
34
- demo.launch(title="Hey NOPE",
35
- theme="monochrome",
36
- description="Welcome to the world of NOPE",
37
- examples=["Need some content Idea", "Generate some Thumbnail Text"])
 
 
 
38
 
39
  if __name__ == "__main__":
40
- demo.launch()
 
2
  import gradio as gr
3
  from groq import Groq
4
 
5
+
6
  client = Groq(
7
  api_key=os.environ.get("GROQ_API_KEY"),
8
  )
9
 
10
+
11
+
12
  def chat_with_groq(user_input, additional_context=None):
13
  chat_completion = client.chat.completions.create(
14
+ messages=[
15
+ {
16
+ "role": "user",
17
+ "content": user_input,
18
+ }
19
+ ],
20
+ model="llama-3.1-8b-instant",
21
+ )
22
  return chat_completion.choices[0].message.content
23
 
 
 
 
 
24
 
 
 
 
 
25
 
 
 
26
 
27
+ demo = gr.ChatInterface(fn=chat_with_groq,
28
+ textbox=gr.Textbox(placeholder="Ask me any question"),
29
+ title="Hey NOPE", theme="Monochrome", description="Welcome to the world of NOPE",
30
+ examples=["Need some content Idea", "Generate some Thumbnail Text"],
31
+ retry_btn=None,
32
+ undo_btn="Delete Previous",
33
+ clear_btn="Clear",)
34
 
35
  if __name__ == "__main__":
36
+ demo.launch()