Abhlash commited on
Commit
06e8d70
·
verified ·
1 Parent(s): 5244724

initial commit for the basic flow of chat bot using groq

Browse files
Files changed (1) hide show
  1. app.py +48 -7
app.py CHANGED
@@ -1,12 +1,53 @@
 
 
 
1
  import gradio as gr
2
 
3
- def greet(name, intensity):
4
- return "Hello, " + name + "!" * int(intensity)
5
 
6
- demo = gr.Interface(
7
- fn=greet,
8
- inputs=["text", "slider"],
9
- outputs=["text"],
10
  )
11
 
12
- demo.launch(share=True)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ from dotenv import load_dotenv
3
+ from groq import Groq
4
  import gradio as gr
5
 
 
 
6
 
7
+ load_dotenv()
8
+ client = Groq(
9
+ # This is the default and can be omitted
10
+ api_key=os.environ.get("GROQ_API_KEY"),
11
  )
12
 
13
+ chat_completion = client.chat.completions.create(
14
+ messages=[
15
+ {
16
+ "role": "system",
17
+ "content": "you are a healthy chef who is going to converse with user and provide recipes",
18
+ },
19
+ {
20
+ "role": "user",
21
+ "content": "give me healthy recipe",
22
+ },
23
+ ],
24
+ model="llama3-70b-8192",
25
+ )
26
+
27
+ print(chat_completion.choices[0].message.content)
28
+
29
+ def chat_with_groq(input_text,additional_info = None):
30
+ chat_completion = client.chat.completions.create(
31
+ messages=[
32
+ {
33
+ "role": "system",
34
+ "content": "you are a healthy chef who is going to converse with user and provide recipes",
35
+ },
36
+ {
37
+ "role": "user",
38
+ "content": input_text,
39
+ },
40
+ ],
41
+ model="llama3-70b-8192",
42
+ )
43
+ return chat_completion.choices[0].message.content
44
+
45
+
46
+ iface = gr.ChatInterface(
47
+ fn=chat_with_groq,
48
+ title="What do you feel like eating today?",
49
+ description="Ask me what you'd like to eat!"
50
+ )
51
+
52
+ if __name__=="__main__":
53
+ iface.launch(share=True)