amkj84 commited on
Commit
90cd621
·
verified ·
1 Parent(s): 9dea61e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +8 -31
app.py CHANGED
@@ -11,10 +11,15 @@ client = Groq(api_key=apikey)
11
  # Function to interact with the LLM using Groq's API
12
  def chatbot(messages):
13
  try:
 
14
  if not messages:
15
- messages = []
16
 
17
- user_input = messages[-1][0] if messages else ""
 
 
 
 
18
 
19
  # Sending request to Groq API
20
  chat_completion = client.chat.completions.create(
@@ -42,32 +47,4 @@ with gr.Blocks(theme=gr.themes.Soft()) as iface:
42
  # Real-Time Text-to-Text Chatbot
43
  **by ATIF MEHMOOD**
44
 
45
- Chat with an advanced language model using Groq's API. Enjoy real-time interactions!
46
- """
47
- )
48
-
49
- with gr.Row():
50
- chatbot_ui = gr.Chatbot(label="Chat Interface", height=400)
51
-
52
- with gr.Row():
53
- user_input = gr.Textbox(
54
- label="Type Your Message",
55
- placeholder="Ask me something...",
56
- lines=1,
57
- interactive=True,
58
- )
59
- send_button = gr.Button("Send", variant="primary")
60
- clear_button = gr.Button("Clear Chat")
61
-
62
- with gr.Row():
63
- gr.Examples(
64
- examples=["Hello!", "Tell me a joke.", "What's the weather like?"],
65
- inputs=user_input,
66
- )
67
-
68
- # Link components to functions
69
- send_button.click(chatbot, inputs=[chatbot_ui], outputs=chatbot_ui)
70
- clear_button.click(reset_chat, inputs=[], outputs=chatbot_ui)
71
-
72
- # Launch the Gradio app
73
- iface.launch()
 
11
  # Function to interact with the LLM using Groq's API
12
  def chatbot(messages):
13
  try:
14
+ # Ensure the messages list is not empty
15
  if not messages:
16
+ messages = [("System", "Hello! How can I assist you today?")]
17
 
18
+ user_input = messages[-1][0] # Last user input message
19
+
20
+ if not user_input.strip(): # Check for empty input
21
+ messages.append(("System", "It seems like you may have accidentally sent an empty message. Please rephrase."))
22
+ return messages
23
 
24
  # Sending request to Groq API
25
  chat_completion = client.chat.completions.create(
 
47
  # Real-Time Text-to-Text Chatbot
48
  **by ATIF MEHMOOD**
49
 
50
+