Spaces:
Running
Running
Upload folder using huggingface_hub
Browse files- components/ChatPage.tsx +17 -12
- server.cjs +42 -0
- verify_final_live.py +36 -0
components/ChatPage.tsx
CHANGED
|
@@ -222,22 +222,27 @@ const ChatPage: React.FC<ChatPageProps> = ({ onBack, simulationResult, setSimula
|
|
| 222 |
return;
|
| 223 |
}
|
| 224 |
|
| 225 |
-
setIsSimulating(true);
|
| 226 |
try {
|
| 227 |
-
|
| 228 |
-
|
| 229 |
-
|
| 230 |
-
|
| 231 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 232 |
|
| 233 |
-
if (
|
| 234 |
-
|
| 235 |
-
} else {
|
| 236 |
-
alert("Crafted suggestion: " + JSON.stringify(result));
|
| 237 |
}
|
| 238 |
-
|
|
|
|
|
|
|
| 239 |
console.error(e);
|
| 240 |
-
alert("Failed to craft content.
|
| 241 |
} finally {
|
| 242 |
setIsSimulating(false);
|
| 243 |
}
|
|
|
|
| 222 |
return;
|
| 223 |
}
|
| 224 |
|
| 225 |
+
setIsSimulating(true);
|
| 226 |
try {
|
| 227 |
+
const response = await fetch('/api/craft', {
|
| 228 |
+
method: 'POST',
|
| 229 |
+
headers: { 'Content-Type': 'application/json' },
|
| 230 |
+
body: JSON.stringify({
|
| 231 |
+
content: msg,
|
| 232 |
+
variation: selectedVariation
|
| 233 |
+
})
|
| 234 |
+
});
|
| 235 |
+
|
| 236 |
+
const data = await response.json();
|
| 237 |
|
| 238 |
+
if (!response.ok) {
|
| 239 |
+
throw new Error(data.error || 'Failed to craft content');
|
|
|
|
|
|
|
| 240 |
}
|
| 241 |
+
|
| 242 |
+
alert(`Crafted variants for ${selectedVariation || 'general content'}:\n\n` + data.result);
|
| 243 |
+
} catch (e: any) {
|
| 244 |
console.error(e);
|
| 245 |
+
alert("Failed to craft content: " + e.message);
|
| 246 |
} finally {
|
| 247 |
setIsSimulating(false);
|
| 248 |
}
|
server.cjs
CHANGED
|
@@ -3,8 +3,50 @@ const path = require('path');
|
|
| 3 |
const app = express();
|
| 4 |
const port = 7860;
|
| 5 |
|
|
|
|
| 6 |
app.use(express.static(path.join(__dirname, 'dist')));
|
| 7 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 8 |
app.get('/api/config', (req, res) => {
|
| 9 |
res.json({
|
| 10 |
clientId: process.env.OAUTH_CLIENT_ID,
|
|
|
|
| 3 |
const app = express();
|
| 4 |
const port = 7860;
|
| 5 |
|
| 6 |
+
app.use(express.json());
|
| 7 |
app.use(express.static(path.join(__dirname, 'dist')));
|
| 8 |
|
| 9 |
+
app.post('/api/craft', async (req, res) => {
|
| 10 |
+
const { content, variation } = req.body;
|
| 11 |
+
const apiKey = process.env.BLABLADOR_API_KEY;
|
| 12 |
+
|
| 13 |
+
if (!apiKey) {
|
| 14 |
+
return res.status(500).json({ error: 'BLABLADOR_API_KEY is not configured on the server.' });
|
| 15 |
+
}
|
| 16 |
+
|
| 17 |
+
const model = content.length > 500 ? 'alias-large' : 'alias-fast';
|
| 18 |
+
const prompt = `You are a professional content creator. Help me craft a ${variation || 'social media post'} based on the following content:\n\n${content}\n\nProvide 3 distinct and engaging variations.`;
|
| 19 |
+
|
| 20 |
+
try {
|
| 21 |
+
const response = await fetch('https://api.helmholtz-blablador.fz-juelich.de/v1/chat/completions', {
|
| 22 |
+
method: 'POST',
|
| 23 |
+
headers: {
|
| 24 |
+
'Authorization': `Bearer ${apiKey}`,
|
| 25 |
+
'Content-Type': 'application/json'
|
| 26 |
+
},
|
| 27 |
+
body: JSON.stringify({
|
| 28 |
+
model: model,
|
| 29 |
+
messages: [
|
| 30 |
+
{ role: 'system', content: 'You are a helpful assistant that helps craft engaging marketing and social media content.' },
|
| 31 |
+
{ role: 'user', content: prompt }
|
| 32 |
+
],
|
| 33 |
+
temperature: 0.7
|
| 34 |
+
})
|
| 35 |
+
});
|
| 36 |
+
|
| 37 |
+
if (!response.ok) {
|
| 38 |
+
const errorData = await response.json();
|
| 39 |
+
return res.status(response.status).json(errorData);
|
| 40 |
+
}
|
| 41 |
+
|
| 42 |
+
const data = await response.json();
|
| 43 |
+
res.json({ result: data.choices[0].message.content });
|
| 44 |
+
} catch (error) {
|
| 45 |
+
console.error('Blablador API error:', error);
|
| 46 |
+
res.status(500).json({ error: 'Failed to connect to Blablador API.' });
|
| 47 |
+
}
|
| 48 |
+
});
|
| 49 |
+
|
| 50 |
app.get('/api/config', (req, res) => {
|
| 51 |
res.json({
|
| 52 |
clientId: process.env.OAUTH_CLIENT_ID,
|
verify_final_live.py
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from playwright.sync_api import sync_playwright
|
| 2 |
+
import os
|
| 3 |
+
|
| 4 |
+
def run():
|
| 5 |
+
with sync_playwright() as p:
|
| 6 |
+
browser = p.chromium.launch(headless=True)
|
| 7 |
+
page = browser.new_page()
|
| 8 |
+
|
| 9 |
+
url = "https://auxteam-usersyncinterface.hf.space"
|
| 10 |
+
print(f"Navigating to {url}...")
|
| 11 |
+
try:
|
| 12 |
+
page.goto(url, timeout=90000)
|
| 13 |
+
page.wait_for_selector('text=Branding Content Testing', timeout=60000)
|
| 14 |
+
|
| 15 |
+
# Scroll to bottom to ensure info box is visible
|
| 16 |
+
page.evaluate("document.querySelector('aside').scrollTop = document.querySelector('aside').scrollHeight")
|
| 17 |
+
page.wait_for_timeout(1000)
|
| 18 |
+
|
| 19 |
+
os.makedirs("/home/jules/verification", exist_ok=True)
|
| 20 |
+
page.screenshot(path="/home/jules/verification/final_landing.png", full_page=True)
|
| 21 |
+
|
| 22 |
+
print("Clicking Open Global Chat...")
|
| 23 |
+
page.click('text=Open Global Chat')
|
| 24 |
+
page.wait_for_selector('text=New Simulation', timeout=20000)
|
| 25 |
+
|
| 26 |
+
page.screenshot(path="/home/jules/verification/final_chat.png", full_page=True)
|
| 27 |
+
print("Verification successful.")
|
| 28 |
+
|
| 29 |
+
except Exception as e:
|
| 30 |
+
print(f"Error: {e}")
|
| 31 |
+
page.screenshot(path="/home/jules/verification/final_error.png")
|
| 32 |
+
|
| 33 |
+
browser.close()
|
| 34 |
+
|
| 35 |
+
if __name__ == "__main__":
|
| 36 |
+
run()
|