Spaces:
Running
Running
Create apps/trend_cat.js
Browse files- apps/trend_cat.js +61 -0
apps/trend_cat.js
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import express from 'express';
|
| 2 |
+
import { generateCompletion, streamCompletion } from '../ai_engine.js';
|
| 3 |
+
// import { createClient } from '@supabase/supabase-js';
|
| 4 |
+
|
| 5 |
+
const router = express.Router();
|
| 6 |
+
|
| 7 |
+
// const supabase = createClient(process.env.SUPABASE_URL, process.env.SUPABASE_KEY);
|
| 8 |
+
|
| 9 |
+
const TREND_CAT_SYSTEM_PROMPT = `You are Trend Cat, an elite TikTok and Instagram Reels growth hacker.
|
| 10 |
+
Your goal is to analyze transcripts or ideas and output highly engaging, retention-optimized video scripts.
|
| 11 |
+
Always include a viral hook framework. Be engaging, witty, and format your output in clean Markdown.`;
|
| 12 |
+
|
| 13 |
+
// Basic generation endpoint for Trend Cat
|
| 14 |
+
router.post('/remix', async (req, res) => {
|
| 15 |
+
const { transcript, niche, model } = req.body;
|
| 16 |
+
|
| 17 |
+
// Example: Supabase Rate Limiting / DB logic could go here
|
| 18 |
+
// const { data, error } = await supabase.from('usage_logs').insert([...]);
|
| 19 |
+
|
| 20 |
+
const prompt = `Here is a transcript of a viral video: \n"${transcript}"\n\nAnalyze why this went viral, extract the psychological hook, and rewrite a script using this exact framework for the "${niche}" niche.`;
|
| 21 |
+
|
| 22 |
+
try {
|
| 23 |
+
const result = await generateCompletion({
|
| 24 |
+
model: model || "maverick", // Defaults to cheap Maverick 17B
|
| 25 |
+
prompt: prompt,
|
| 26 |
+
system_prompt: TREND_CAT_SYSTEM_PROMPT,
|
| 27 |
+
images:[]
|
| 28 |
+
});
|
| 29 |
+
res.json(result);
|
| 30 |
+
} catch (err) {
|
| 31 |
+
console.error(`❌ [Trend Cat Generate Error]:`, err.message);
|
| 32 |
+
res.status(500).json({ success: false, error: err.message });
|
| 33 |
+
}
|
| 34 |
+
});
|
| 35 |
+
|
| 36 |
+
// Streaming endpoint for Trend Cat (for real-time UI typing effect)
|
| 37 |
+
router.post('/stream-remix', async (req, res) => {
|
| 38 |
+
const { transcript, niche, model } = req.body;
|
| 39 |
+
const prompt = `Here is a transcript of a viral video: \n"${transcript}"\n\nRewrite this viral script for the "${niche}" niche. Provide the Hook, Body, and Call to Action.`;
|
| 40 |
+
|
| 41 |
+
res.setHeader('Content-Type', 'text/plain; charset=utf-8');
|
| 42 |
+
res.setHeader('Transfer-Encoding', 'chunked');
|
| 43 |
+
res.setHeader('X-Accel-Buffering', 'no');
|
| 44 |
+
res.flushHeaders();
|
| 45 |
+
|
| 46 |
+
try {
|
| 47 |
+
await streamCompletion({
|
| 48 |
+
model: model || "maverick",
|
| 49 |
+
prompt: prompt,
|
| 50 |
+
system_prompt: TREND_CAT_SYSTEM_PROMPT,
|
| 51 |
+
images:[],
|
| 52 |
+
res: res
|
| 53 |
+
});
|
| 54 |
+
} catch (err) {
|
| 55 |
+
console.error(`❌ [Trend Cat Stream Error]:`, err.message);
|
| 56 |
+
res.write(`ERROR: ${err.message}`);
|
| 57 |
+
res.end();
|
| 58 |
+
}
|
| 59 |
+
});
|
| 60 |
+
|
| 61 |
+
export default router;
|