Unizomby commited on
Commit
e420025
·
verified ·
1 Parent(s): 5e10ee5

Upload app.py

Browse files
Files changed (1) hide show
  1. app.py +37 -147
app.py CHANGED
@@ -20,158 +20,48 @@ def chatbot_response(message):
20
  response = query_engine.query(message)
21
  return str(response)
22
 
23
- # Custom CSS for purple button styling with JavaScript
24
- custom_css = """
25
- /* Target all possible Gradio button selectors */
26
- button,
27
- .btn,
28
- .gr-button,
29
- .gradio-button,
30
- input[type="submit"],
31
- .submit-btn {
32
- background: linear-gradient(45deg, #8B5CF6, #A855F7) !important;
33
- border: none !important;
34
- color: white !important;
35
- border-radius: 8px !important;
36
- }
37
-
38
- button:hover,
39
- .btn:hover,
40
- .gr-button:hover,
41
- .gradio-button:hover,
42
- input[type="submit"]:hover,
43
- .submit-btn:hover {
44
- background: linear-gradient(45deg, #7C3AED, #9333EA) !important;
45
- transform: translateY(-2px) !important;
46
- box-shadow: 0 4px 12px rgba(139, 92, 246, 0.3) !important;
47
- transition: all 0.2s ease !important;
48
- }
49
-
50
- /* Specific targeting for different Gradio versions */
51
- .gradio-container button,
52
- .gradio-container .btn {
53
- background: linear-gradient(45deg, #8B5CF6, #A855F7) !important;
54
- border: none !important;
55
- color: white !important;
56
- }
57
-
58
- .gradio-container button:hover,
59
- .gradio-container .btn:hover {
60
- background: linear-gradient(45deg, #7C3AED, #9333EA) !important;
61
- }
62
-
63
- /* Target by CSS classes that might be used */
64
- .primary,
65
- .btn-primary,
66
- .gr-button-primary {
67
- background: linear-gradient(45deg, #8B5CF6, #A855F7) !important;
68
- border: none !important;
69
- color: white !important;
70
- }
71
-
72
- .primary:hover,
73
- .btn-primary:hover,
74
- .gr-button-primary:hover {
75
- background: linear-gradient(45deg, #7C3AED, #9333EA) !important;
76
- }
77
-
78
- /* Very specific targeting for submit-like buttons */
79
- button[aria-label*="Submit"],
80
- button[title*="Submit"],
81
- .submit,
82
- .gr-form button {
83
- background: linear-gradient(45deg, #8B5CF6, #A855F7) !important;
84
- border: none !important;
85
- color: white !important;
86
- }
87
 
88
- /* Override any orange/default styling */
89
- .gradio-button.primary,
90
- .btn.primary,
91
- button.primary {
92
- background: linear-gradient(45deg, #8B5CF6, #A855F7) !important;
93
- border: none !important;
94
  color: white !important;
 
95
  }
96
-
97
- /* Clear/secondary buttons */
98
- .secondary,
99
- .btn-secondary,
100
- .gr-button-secondary {
101
- background: #E5E7EB !important;
102
- color: #374151 !important;
103
- border: 1px solid #D1D5DB !important;
104
- }
105
-
106
- .secondary:hover,
107
- .btn-secondary:hover,
108
- .gr-button-secondary:hover {
109
- background: #F3F4F6 !important;
110
- }
111
-
112
- /* JavaScript to style example buttons */
113
- <script>
114
- function styleExampleButtons() {
115
- // Wait for the page to fully load
116
- setTimeout(function() {
117
- console.log('Attempting to style example buttons...');
118
-
119
- // Find all buttons on the page
120
- const allButtons = document.querySelectorAll('button');
121
- console.log('Found', allButtons.length, 'buttons');
122
-
123
- // Skip the first two buttons (Clear and Submit) and style the rest
124
- allButtons.forEach((btn, index) => {
125
- if (index >= 2) {
126
- console.log('Styling button', index, ':', btn.textContent);
127
- btn.style.setProperty('background', '#374151', 'important');
128
- btn.style.setProperty('color', 'white', 'important');
129
- btn.style.setProperty('border', '1px solid #4B5563', 'important');
130
- btn.style.setProperty('border-radius', '8px', 'important');
131
-
132
- // Add hover effect
133
- btn.addEventListener('mouseenter', function() {
134
- this.style.setProperty('background', '#4B5563', 'important');
135
- });
136
- btn.addEventListener('mouseleave', function() {
137
- this.style.setProperty('background', '#374151', 'important');
138
- });
139
- }
140
- });
141
-
142
- // Alternative approach: look for buttons containing example text
143
- const exampleTexts = [
144
- 'Provide a summary of Donald',
145
- 'Has Donald worked with Python',
146
- 'Tell me something interesting',
147
- 'What technical skills',
148
- 'How did Donald build'
149
- ];
150
-
151
- exampleTexts.forEach(text => {
152
- const buttons = Array.from(allButtons).filter(btn =>
153
- btn.textContent.includes(text) ||
154
- btn.innerText.includes(text)
155
- );
156
- buttons.forEach(btn => {
157
- console.log('Found example button:', btn.textContent);
158
- btn.style.setProperty('background', '#374151', 'important');
159
- btn.style.setProperty('color', 'white', 'important');
160
- btn.style.setProperty('border', '1px solid #4B5563', 'important');
161
- });
162
- });
163
- }, 2000); // Wait 2 seconds for Gradio to fully render
164
- }
165
-
166
- // Run immediately and also when DOM content loads
167
- styleExampleButtons();
168
- document.addEventListener('DOMContentLoaded', styleExampleButtons);
169
-
170
- // Also run when the window loads (backup)
171
- window.addEventListener('load', styleExampleButtons);
172
- </script>
173
  """
174
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
175
  iface = gr.Interface(
176
  fn=chatbot_response,
177
  inputs="text",
 
20
  response = query_engine.query(message)
21
  return str(response)
22
 
23
+ # Create a custom theme with purple buttons
24
+ custom_theme = gr.themes.Soft(
25
+ primary_hue=gr.themes.colors.purple,
26
+ secondary_hue=gr.themes.colors.gray,
27
+ neutral_hue=gr.themes.colors.gray,
28
+ ).set(
29
+ button_primary_background_fill="linear-gradient(45deg, #8B5CF6, #A855F7)",
30
+ button_primary_background_fill_hover="linear-gradient(45deg, #7C3AED, #9333EA)",
31
+ button_primary_text_color="white",
32
+ button_primary_border_color="transparent",
33
+ button_secondary_background_fill="#374151",
34
+ button_secondary_background_fill_hover="#4B5563",
35
+ button_secondary_text_color="white",
36
+ button_secondary_border_color="#4B5563",
37
+ )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
38
 
39
+ # Minimal CSS as backup
40
+ custom_css = """
41
+ /* Backup styling for example buttons */
42
+ .examples button {
43
+ background: #374151 !important;
 
44
  color: white !important;
45
+ border: 1px solid #4B5563 !important;
46
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
47
  """
48
 
49
+ iface = gr.Interface(
50
+ fn=chatbot_response,
51
+ inputs="text",
52
+ outputs="text",
53
+ title="Ask about me",
54
+ description="Ask questions and receive answers based on my bio.",
55
+ examples=[["Provide a summary of Donald"],
56
+ ["Has Donald worked with Python or machine learning?"],
57
+ ["Tell me something interesting about Donald"],
58
+ ["What technical skills does Donald have?"],
59
+ ["How did Donald build this RAG chatbot?"]
60
+ ],
61
+ theme=custom_theme,
62
+ css=custom_css
63
+ )
64
+
65
  iface = gr.Interface(
66
  fn=chatbot_response,
67
  inputs="text",