Solarum Asteridion commited on
Commit
57df4e3
·
verified ·
1 Parent(s): 2e9a495

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +27 -10
app.py CHANGED
@@ -2,6 +2,7 @@ import openai
2
  import datetime
3
  import pytz
4
  import gradio as gr
 
5
 
6
  # Your real API key (replace with yours if different)
7
  client = openai.OpenAI(
@@ -10,7 +11,7 @@ client = openai.OpenAI(
10
  )
11
 
12
  def get_current_local_time():
13
- return datetime.datetime.now().strftime("%a, %d %b %Y %H:%M:%S")
14
 
15
  def generate_response(user_message, conversation_history):
16
  current_time = get_current_local_time()
@@ -58,14 +59,19 @@ Make it a challenge to guess if you are an AI.
58
  def chatbot_interface(input, history):
59
  history = history or []
60
  user_message = input
61
- ai_response = generate_response(user_message, history)
62
- history.append((user_message, ai_response))
 
 
 
 
 
63
  return history, history
64
 
65
- # CSS for styling the interface
66
  css = """
67
  body {
68
- font-family: 'Merriweather', serif;
69
  }
70
  #chatbot {
71
  border: 1px solid #ccc;
@@ -79,6 +85,7 @@ body {
79
  padding: 10px;
80
  margin-bottom: 5px;
81
  border-radius: 5px;
 
82
  }
83
  .ai-message {
84
  background-color: #f5f5dc;
@@ -86,6 +93,10 @@ body {
86
  margin-bottom: 5px;
87
  border-radius: 5px;
88
  }
 
 
 
 
89
  #textbox {
90
  margin-top: 10px;
91
  }
@@ -93,14 +104,20 @@ body {
93
 
94
  # Create the Gradio interface
95
  with gr.Blocks(css=css) as demo:
96
-
 
97
  with gr.Row():
98
- chatbot = gr.Chatbot(elem_id="chatbot")
99
 
100
  with gr.Row():
101
- msg = gr.Textbox(placeholder="Enter your message here...", elem_id="textbox")
102
- submit_btn = gr.Button("Send", variant="primary") # Primary button style
103
- clear_btn = gr.Button("Clear", variant="secondary") # Secondary button style
 
 
 
 
 
104
 
105
  def user(user_message, history):
106
  return "", history + [[user_message, None]]
 
2
  import datetime
3
  import pytz
4
  import gradio as gr
5
+ import time
6
 
7
  # Your real API key (replace with yours if different)
8
  client = openai.OpenAI(
 
11
  )
12
 
13
  def get_current_local_time():
14
+ return datetime.datetime.now().strftime("%I:%M %p") # Format time as 09:32 PM
15
 
16
  def generate_response(user_message, conversation_history):
17
  current_time = get_current_local_time()
 
59
  def chatbot_interface(input, history):
60
  history = history or []
61
  user_message = input
62
+
63
+ # Simulate typing animation by adding a delay
64
+ history.append((user_message, "Typing..."))
65
+ time.sleep(2) # Adjust the delay as needed
66
+
67
+ ai_response = generate_response(user_message, history[:-1])
68
+ history[-1] = (user_message, ai_response) # Replace "Typing..." with the actual response
69
  return history, history
70
 
71
+ # CSS for styling the interface (including typing animation)
72
  css = """
73
  body {
74
+ font-family: 'Merriweather', serif;
75
  }
76
  #chatbot {
77
  border: 1px solid #ccc;
 
85
  padding: 10px;
86
  margin-bottom: 5px;
87
  border-radius: 5px;
88
+ text-align: right; /* Align user messages to the right */
89
  }
90
  .ai-message {
91
  background-color: #f5f5dc;
 
93
  margin-bottom: 5px;
94
  border-radius: 5px;
95
  }
96
+ .typing-indicator { /* Style for the typing animation */
97
+ font-style: italic;
98
+ color: #888;
99
+ }
100
  #textbox {
101
  margin-top: 10px;
102
  }
 
104
 
105
  # Create the Gradio interface
106
  with gr.Blocks(css=css) as demo:
107
+ gr.Markdown("<h1>AI Chatbot Challenge</h1>")
108
+
109
  with gr.Row():
110
+ chatbot = gr.Chatbot(elem_id="chatbot")
111
 
112
  with gr.Row():
113
+ msg = gr.Textbox(placeholder="Type here...", elem_id="textbox")
114
+ submit_btn = gr.Button("Send", variant="primary")
115
+ clear_btn = gr.Button("Clear", variant="secondary")
116
+
117
+ # Add icons to the buttons (using FontAwesome for example)
118
+ with gr.Accordion("More Options", open=False):
119
+ upload_btn = gr.UploadButton("Upload File", file_types=["image", "video", "audio"])
120
+ record_btn = gr.Button("Record Audio", variant="secondary")
121
 
122
  def user(user_message, history):
123
  return "", history + [[user_message, None]]