Laibaaaaa commited on
Commit
eb42842
·
verified ·
1 Parent(s): cb4e9e6

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +13 -12
app.py CHANGED
@@ -13,19 +13,14 @@ You explain data science, machine learning,
13
  statistics, Python, and big data concepts clearly.
14
  """
15
 
16
- def query_groq(user_message, chat_history):
17
  headers = {
18
  "Authorization": f"Bearer {GROQ_API_KEY}",
19
  "Content-Type": "application/json"
20
  }
21
 
22
  messages = [{"role": "system", "content": SYSTEM_PROMPT}]
23
-
24
- for user, bot in chat_history:
25
- messages.append({"role": "user", "content": user})
26
- messages.append({"role": "assistant", "content": bot})
27
-
28
- messages.append({"role": "user", "content": user_message})
29
 
30
  response = requests.post(
31
  GROQ_API_URL,
@@ -42,15 +37,22 @@ def query_groq(user_message, chat_history):
42
  else:
43
  return "❌ Error connecting to GROQ API"
44
 
45
- def respond(message, chat_history):
46
- reply = query_groq(message, chat_history)
47
- chat_history.append((message, reply))
 
 
 
 
 
 
 
48
  return chat_history, chat_history
49
 
50
  with gr.Blocks() as demo:
51
  gr.Markdown("## 📊 Data Science Tutor Chatbot")
52
 
53
- chatbot = gr.Chatbot(type="tuples")
54
  msg = gr.Textbox(label="Ask your question")
55
  clear = gr.Button("Clear Chat")
56
 
@@ -60,4 +62,3 @@ with gr.Blocks() as demo:
60
  clear.click(lambda: ([], []), None, [chatbot, state])
61
 
62
  demo.launch()
63
-
 
13
  statistics, Python, and big data concepts clearly.
14
  """
15
 
16
+ def query_groq(chat_history):
17
  headers = {
18
  "Authorization": f"Bearer {GROQ_API_KEY}",
19
  "Content-Type": "application/json"
20
  }
21
 
22
  messages = [{"role": "system", "content": SYSTEM_PROMPT}]
23
+ messages.extend(chat_history)
 
 
 
 
 
24
 
25
  response = requests.post(
26
  GROQ_API_URL,
 
37
  else:
38
  return "❌ Error connecting to GROQ API"
39
 
40
+ def respond(user_message, chat_history):
41
+ # add user message
42
+ chat_history.append({"role": "user", "content": user_message})
43
+
44
+ # get bot reply
45
+ reply = query_groq(chat_history)
46
+
47
+ # add assistant reply
48
+ chat_history.append({"role": "assistant", "content": reply})
49
+
50
  return chat_history, chat_history
51
 
52
  with gr.Blocks() as demo:
53
  gr.Markdown("## 📊 Data Science Tutor Chatbot")
54
 
55
+ chatbot = gr.Chatbot()
56
  msg = gr.Textbox(label="Ask your question")
57
  clear = gr.Button("Clear Chat")
58
 
 
62
  clear.click(lambda: ([], []), None, [chatbot, state])
63
 
64
  demo.launch()