Spaces:
Running
Running
Create App.js.
Browse files
App.js.
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
const API_URL = "https://router.huggingface.co/v1/chat/completions";
|
| 3 |
+
|
| 4 |
+
async function generateScript(prompt) {
|
| 5 |
+
const response = await fetch(API_URL, {
|
| 6 |
+
method: "POST",
|
| 7 |
+
headers: {
|
| 8 |
+
"Content-Type": "application/json",
|
| 9 |
+
"Authorization": "Bearer " + HF_TOKEN
|
| 10 |
+
},
|
| 11 |
+
body: JSON.stringify({
|
| 12 |
+
model: "Qwen/Qwen2.5-7B-Instruct",
|
| 13 |
+
messages: [
|
| 14 |
+
{
|
| 15 |
+
role: "user",
|
| 16 |
+
content: prompt
|
| 17 |
+
}
|
| 18 |
+
],
|
| 19 |
+
max_tokens: 500
|
| 20 |
+
})
|
| 21 |
+
});
|
| 22 |
+
|
| 23 |
+
if (!response.ok) {
|
| 24 |
+
throw new Error("AI generation failed: " + response.status);
|
| 25 |
+
}
|
| 26 |
+
|
| 27 |
+
const data = await response.json();
|
| 28 |
+
return data.choices[0].message.content;
|
| 29 |
+
}
|