Pinkstack commited on
Commit
a6f10c7
·
verified ·
1 Parent(s): 2131841

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +34 -9
app.py CHANGED
@@ -44,10 +44,26 @@ def respond(
44
  yield f"Error: {str(e)}"
45
 
46
  def format_response(response: str) -> str:
47
- """Format the response with collapsible thinking sections"""
48
- response = response.replace("<think>", '<details open><summary>Show thinking 🧠</summary><div class="thoughts">')
49
- response = response.replace("</think>", "</div></details>")
50
- return response
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
51
 
52
  # Custom CSS for styling
53
  css = """
@@ -81,8 +97,8 @@ details[open] summary:after {
81
 
82
  # Create Gradio interface
83
  with gr.Blocks(css=css) as demo:
84
- gr.Markdown("# Chat with Superthoughts lite! (1.7B)")
85
- gr.Markdown("**Warning:** The first output from the AI may take a few moments. After the first message, it should work at a decent speed, keep in mind that this chat is only meant for testing and experimenting.")
86
 
87
  chatbot = gr.Chatbot(height=600)
88
  msg = gr.Textbox(label="Your message", placeholder="Type your message here...")
@@ -139,9 +155,18 @@ with gr.Blocks(css=css) as demo:
139
  chatbot
140
  )
141
 
142
- # Add a clear button
143
- clear = gr.Button("Clear Conversation")
144
- clear.click(lambda: None, None, chatbot, queue=False)
 
 
 
 
 
 
 
 
 
145
 
146
  # Launch the interface
147
  if __name__ == "__main__":
 
44
  yield f"Error: {str(e)}"
45
 
46
  def format_response(response: str) -> str:
47
+ """Format the response with collapsible thinking sections that maintain state"""
48
+ import re
49
+ import hashlib
50
+
51
+ def get_section_id(content):
52
+ # Create a unique ID for each thinking section based on its content
53
+ return hashlib.md5(content.encode()).hexdigest()[:8]
54
+
55
+ # Find all thinking sections and replace them with uniquely identified sections
56
+ pattern = r"<think>(.*?)</think>"
57
+ sections = re.findall(pattern, response, re.DOTALL)
58
+
59
+ formatted = response
60
+ for section in sections:
61
+ section_id = get_section_id(section)
62
+ old = f"<think>{section}</think>"
63
+ new = f'<details id="think_{section_id}" open><summary>Show thinking 🧠</summary><div class="thoughts">{section}</div></details>'
64
+ formatted = formatted.replace(old, new)
65
+
66
+ return formatted
67
 
68
  # Custom CSS for styling
69
  css = """
 
97
 
98
  # Create Gradio interface
99
  with gr.Blocks(css=css) as demo:
100
+ gr.Markdown("## Chat with Superthoughts lite! (1.7B)")
101
+ gr.Markdown("**Note:** First response may take a moment to initialize. Subsequent responses will be faster.")
102
 
103
  chatbot = gr.Chatbot(height=600)
104
  msg = gr.Textbox(label="Your message", placeholder="Type your message here...")
 
155
  chatbot
156
  )
157
 
158
+ with gr.Row():
159
+ clear = gr.Button("Clear Conversation")
160
+ stop = gr.Button("Stop Generation")
161
+
162
+ # Add disclaimer
163
+ gr.Markdown(
164
+ """
165
+ ---
166
+ ⚠️ **Disclaimer:** Superthoughts may make mistakes. Always verify important information.
167
+ This chat interface is intended for testing and experimentation purposes only.
168
+ """
169
+ )
170
 
171
  # Launch the interface
172
  if __name__ == "__main__":