arhanovich commited on
Commit
9bbbfc8
1 Parent(s): e540d45

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +40 -0
app.py ADDED
@@ -0,0 +1,40 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """
2
+ If you are running this code, replace API_KEY in config.json with actual api key obtained from https://console.groq.com/keys
3
+ Also, please grab the public URL and then save it into config.json and keep the program runnig.
4
+ """
5
+
6
+ import gradio as gr
7
+ from groq import Groq
8
+
9
+ api_key = config['API_KEY']
10
+ if api_key == "your-api-key-here":
11
+ print("Please replac API_KEY in config.json with actual api key obtained from https://console.groq.com/keys")
12
+ else:
13
+ client = Groq(api_key=api_key)
14
+
15
+ messages = [
16
+ {"role": "system", "content": "Act as though you are Bart Simpson"}
17
+ ]
18
+ print("!!!!After the launch is done, please grab the public URL and then save it into config.json and keeo the program running")
19
+
20
+ def respond(message, chat_history):
21
+ messages.append({"role": "user", "content": message})
22
+ chat_completion = client.chat.completions.create(
23
+ messages=messages,
24
+ model="llama3-8b-8192",
25
+ )
26
+ bot_message = chat_completion.choices[0].message.content
27
+ messages.append({"role": "assistant", "content": bot_message})
28
+ chat_history.append((message, bot_message))
29
+ return "", chat_history
30
+
31
+ with gr.Blocks() as demo:
32
+ chatbot = gr.Chatbot()
33
+ msg = gr.Textbox(placeholder="Type a message and press Enter")
34
+ clear = gr.ClearButton([msg, chatbot])
35
+
36
+ msg.submit(respond, [msg, chatbot], [msg, chatbot])
37
+
38
+ if __name__ == "__main__":
39
+ demo.launch()
40
+