shukdevdatta123 commited on
Commit
3e5c357
·
verified ·
1 Parent(s): fe9817a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +134 -20
app.py CHANGED
@@ -62,35 +62,149 @@ def chatbot(input_text, image, openai_api_key, reasoning_effort, model_choice, h
62
  def clear_history():
63
  return "", []
64
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
65
  # Gradio interface setup
66
  def create_interface():
67
- with gr.Blocks() as demo:
68
- gr.Markdown("# Multimodal Chatbot (Text + Image)")
69
-
70
- # Add a description after the title
71
  gr.Markdown("""
72
- ### Description:
73
- This is a multimodal chatbot that can handle both text and image inputs.
74
- - You can ask questions or provide text, and the assistant will respond.
75
- - You can also upload an image, and the assistant will process it and answer questions about the image.
76
- - Enter your OpenAI API key to start interacting with the model.
77
- - You can use the 'Clear History' button to remove the conversation history.
78
- - "o1" is for image chat and "o3-mini" is for text chat.
79
-
80
- ### Reasoning Effort:
81
- The reasoning effort controls how complex or detailed the assistant's answers should be.
82
- - **Low**: Provides quick, concise answers with minimal reasoning or details.
83
- - **Medium**: Offers a balanced response with a reasonable level of detail and thought.
84
- - **High**: Produces more detailed, analytical, or thoughtful responses, requiring deeper reasoning.
85
  """)
86
 
87
  with gr.Row():
88
  openai_api_key = gr.Textbox(label="Enter OpenAI API Key", type="password", placeholder="sk-...", interactive=True)
89
-
90
  with gr.Row():
91
  image_input = gr.Image(label="Upload an Image", type="pil") # Image upload input
92
  input_text = gr.Textbox(label="Enter Text Question", placeholder="Ask a question or provide text", lines=2)
93
-
94
  with gr.Row():
95
  reasoning_effort = gr.Dropdown(
96
  label="Reasoning Effort",
@@ -103,7 +217,7 @@ def create_interface():
103
  value="o1" # Default to 'o1' for image-related tasks
104
  )
105
  submit_btn = gr.Button("Send")
106
- clear_btn = gr.Button("Clear History")
107
 
108
  chat_history = gr.Chatbot()
109
 
 
62
  def clear_history():
63
  return "", []
64
 
65
+ # Custom CSS styles with animations
66
+ custom_css = """
67
+ /* General body styles */
68
+ .gradio-container {
69
+ font-family: 'Arial', sans-serif;
70
+ background-color: #f8f9fa;
71
+ color: #333;
72
+ }
73
+
74
+ /* Header styles */
75
+ .gradio-header {
76
+ background-color: #007bff;
77
+ color: white;
78
+ padding: 20px;
79
+ text-align: center;
80
+ border-radius: 8px;
81
+ box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
82
+ animation: fadeIn 1s ease-out;
83
+ }
84
+
85
+ .gradio-header h1 {
86
+ font-size: 2.5rem;
87
+ }
88
+
89
+ .gradio-header h3 {
90
+ font-size: 1.2rem;
91
+ margin-top: 10px;
92
+ }
93
+
94
+ /* Chatbot container styles */
95
+ .gradio-chatbot {
96
+ background-color: #fff;
97
+ border-radius: 10px;
98
+ padding: 20px;
99
+ box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
100
+ max-height: 500px;
101
+ overflow-y: auto;
102
+ animation: fadeIn 2s ease-out;
103
+ }
104
+
105
+ /* Input field styles */
106
+ .gradio-textbox, .gradio-dropdown, .gradio-image {
107
+ border-radius: 8px;
108
+ border: 2px solid #ccc;
109
+ padding: 10px;
110
+ margin-bottom: 10px;
111
+ width: 100%;
112
+ font-size: 1rem;
113
+ transition: all 0.3s ease;
114
+ }
115
+
116
+ .gradio-textbox:focus, .gradio-dropdown:focus, .gradio-image:focus {
117
+ border-color: #007bff;
118
+ }
119
+
120
+ /* Button styles */
121
+ .gradio-button {
122
+ background-color: #007bff;
123
+ color: white;
124
+ border: none;
125
+ border-radius: 8px;
126
+ padding: 12px 20px;
127
+ font-size: 1.1rem;
128
+ cursor: pointer;
129
+ transition: all 0.3s ease;
130
+ }
131
+
132
+ .gradio-button:hover {
133
+ background-color: #0056b3;
134
+ }
135
+
136
+ .gradio-button:active {
137
+ transform: scale(0.95);
138
+ }
139
+
140
+ /* Chat history styles */
141
+ .gradio-chatbot .message {
142
+ margin-bottom: 10px;
143
+ }
144
+
145
+ .gradio-chatbot .user {
146
+ background-color: #007bff;
147
+ color: white;
148
+ padding: 10px;
149
+ border-radius: 12px;
150
+ max-width: 70%;
151
+ animation: slideInUser 0.5s ease-out;
152
+ }
153
+
154
+ .gradio-chatbot .assistant {
155
+ background-color: #f1f1f1;
156
+ color: #333;
157
+ padding: 10px;
158
+ border-radius: 12px;
159
+ max-width: 70%;
160
+ margin-left: auto;
161
+ animation: slideInAssistant 0.5s ease-out;
162
+ }
163
+
164
+ /* Clear button style */
165
+ .gradio-button.clear-history {
166
+ background-color: #dc3545;
167
+ margin-left: 10px;
168
+ }
169
+
170
+ .gradio-button.clear-history:hover {
171
+ background-color: #c82333;
172
+ }
173
+
174
+ /* Animation keyframes */
175
+ @keyframes fadeIn {
176
+ 0% { opacity: 0; }
177
+ 100% { opacity: 1; }
178
+ }
179
+
180
+ @keyframes slideInUser {
181
+ 0% { transform: translateX(-100%); }
182
+ 100% { transform: translateX(0); }
183
+ }
184
+
185
+ @keyframes slideInAssistant {
186
+ 0% { transform: translateX(100%); }
187
+ 100% { transform: translateX(0); }
188
+ }
189
+ """
190
+
191
  # Gradio interface setup
192
  def create_interface():
193
+ with gr.Blocks(css=custom_css) as demo:
 
 
 
194
  gr.Markdown("""
195
+ <div class="gradio-header">
196
+ <h1>Multimodal Chatbot (Text + Image)</h1>
197
+ <h3>Interact with a chatbot using text or image inputs</h3>
198
+ </div>
 
 
 
 
 
 
 
 
 
199
  """)
200
 
201
  with gr.Row():
202
  openai_api_key = gr.Textbox(label="Enter OpenAI API Key", type="password", placeholder="sk-...", interactive=True)
203
+
204
  with gr.Row():
205
  image_input = gr.Image(label="Upload an Image", type="pil") # Image upload input
206
  input_text = gr.Textbox(label="Enter Text Question", placeholder="Ask a question or provide text", lines=2)
207
+
208
  with gr.Row():
209
  reasoning_effort = gr.Dropdown(
210
  label="Reasoning Effort",
 
217
  value="o1" # Default to 'o1' for image-related tasks
218
  )
219
  submit_btn = gr.Button("Send")
220
+ clear_btn = gr.Button("Clear History", class_name="clear-history")
221
 
222
  chat_history = gr.Chatbot()
223