Hugging Face's logo
Hugging Face
Search models, datasets, users...
Models
Datasets
Spaces
Posts
Docs
Solutions
Pricing
Spaces:
Sadmank
/
reflection
private
Logs
App
Files
Community
Settings
reflection
/
app.py
Sadmank's picture
Sadmank
Update app.py
6c53f07
verified
3 minutes ago
raw
Copy download link
history
blame
edit
delete
No virus
5.92 kB
import gradio as gr
import requests
import os
import json
import traceback
import sys
import re
# Enable or disable tracing
ENABLE_TRACING = False
# Set up the API endpoint and key
API_BASE_URL = os.getenv("RUNPOD_API_URL")
API_KEY = os.getenv("RUNPOD_API_KEY")
API_URL = f"{API_BASE_URL}/chat/completions"
headers = {
"Authorization": f"Bearer {API_KEY}",
"Content-Type": "application/json"
}
import re
def style_xml_content(text):
def replace_content(match):
full_match = match.group(0)
tag = match.group(1)
content = match.group(2)
if tag == 'thinking':
styled_content = f'{content}'
return f'<thinking>
{styled_content}
</thinking> '
elif tag == 'reflection':
styled_content = f'{content}'
return f'<reflection>
{styled_content}
</reflection> '
else:
return full_match.replace('<', '<').replace('>', '>')
# First, escape all < and > characters
text = text.replace('<', '<').replace('>', '>')
# Then, unescape the specific tags we want to process
text = text.replace('<thinking>', '').replace('</thinking>', '')
text = text.replace('<reflection>', '').replace('</reflection>', '')
# Apply styling to content inside tags
styled_text = re.sub(r'<(\w+)>(.*?)\1>', replace_content, text, flags=re.DOTALL)
# Remove blacklisted text
styled_text = styled_text.replace("<|im_start|>", "")
return styled_text
# Fixed system prompt
SYSTEM_PROMPT = "You an advanced artificial intelligence system, capable of and then creating a length , where you ask if you were wrong? And then you correct yourself. Always use unless it is a trivial or wikipedia question. Finally you output a brief and small to the point