DHEIVER commited on
Commit
be3a46d
1 Parent(s): d53d57a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +23 -12
app.py CHANGED
@@ -1,12 +1,15 @@
1
- import gradio as gr
2
  from groq import Groq
 
 
3
 
4
  class ConversationalAI:
5
  def __init__(self):
 
6
  self.client = Groq()
7
  self.system_prompt = {
8
  "role": "system",
9
- "content": "You are a useful assistant. You reply with efficient answers."
10
  }
11
 
12
  async def chat_groq(self, message, history):
@@ -21,12 +24,12 @@ class ConversationalAI:
21
  response_content = ''
22
 
23
  stream = self.client.chat.completions.create(
24
- model="llama3-70b-8192",
25
- messages=messages,
26
- max_tokens=1024,
27
- temperature=1.3,
28
- stream=True
29
- )
30
 
31
  for chunk in stream:
32
  content = chunk.choices[0].delta.content
@@ -34,9 +37,17 @@ class ConversationalAI:
34
  response_content += chunk.choices[0].delta.content
35
  yield response_content
36
 
 
 
 
 
 
 
 
 
 
37
  if __name__ == "__main__":
38
  ai = ConversationalAI()
39
- interface = gr.Interface(ai.chat_groq, inputs=gr.Textbox(label="Message", placeholder="Type your message here..."),
40
- outputs=gr.Textbox(label="Response", placeholder="Response will appear here..."),
41
- theme="compact")
42
- interface.launch()
 
1
+ import os
2
  from groq import Groq
3
+ import gradio as gr
4
+ from config import GROQ_API_KEY
5
 
6
  class ConversationalAI:
7
  def __init__(self):
8
+ os.environ["GROQ_API_KEY"] = GROQ_API_KEY
9
  self.client = Groq()
10
  self.system_prompt = {
11
  "role": "system",
12
+ "content": "You are a useful assistant. You reply with efficient answers. "
13
  }
14
 
15
  async def chat_groq(self, message, history):
 
24
  response_content = ''
25
 
26
  stream = self.client.chat.completions.create(
27
+ model="llama3-70b-8192",
28
+ messages=messages,
29
+ max_tokens=1024,
30
+ temperature=1.3,
31
+ stream=True
32
+ )
33
 
34
  for chunk in stream:
35
  content = chunk.choices[0].delta.content
 
37
  response_content += chunk.choices[0].delta.content
38
  yield response_content
39
 
40
+ def create_chat_interface(self):
41
+ with gr.Blocks(theme=gr.themes.Monochrome(), fill_height=True) as demo:
42
+ gr.ChatInterface(self.chat_groq,
43
+ clear_btn=None,
44
+ undo_btn=None,
45
+ retry_btn=None,
46
+ )
47
+ return demo
48
+
49
  if __name__ == "__main__":
50
  ai = ConversationalAI()
51
+ demo = ai.create_chat_interface()
52
+ demo.queue()
53
+ demo.launch()