forgot to commit this
Browse files
App/Generate/generatorRoutes.py
CHANGED
@@ -1,7 +1,7 @@
|
|
1 |
from fastapi import APIRouter, HTTPException, status, BackgroundTasks, UploadFile, Query
|
2 |
from .Schema import GeneratorRequest
|
3 |
from .utils.GroqInstruct import chatbot, VideoOutput
|
4 |
-
from .utils.HuggingChat import
|
5 |
from .Story.Story import Story
|
6 |
import asyncio, pprint, json
|
7 |
from tqdm import tqdm
|
@@ -19,21 +19,16 @@ async def update_scene(model_scene):
|
|
19 |
async def main(request: GeneratorRequest):
|
20 |
topic = request.prompt
|
21 |
renderr = RenderVideo()
|
|
|
22 |
if request.grok:
|
23 |
message = chatbot(Prompt.format(topic=topic))
|
24 |
|
25 |
else:
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
Prompt.format(topic=topic)
|
30 |
-
+ f"Match your response to the following schema: {VideoOutput.model_json_schema()} Make sure to return an instance of the JSON, not the schema itself, and nothing else."
|
31 |
-
)
|
32 |
-
)
|
33 |
-
.split("```json")[1]
|
34 |
-
.split("```")[0]
|
35 |
-
.strip()
|
36 |
)
|
|
|
37 |
generated_story = Story.from_dict(message["scenes"])
|
38 |
|
39 |
print("Generated Story ✅")
|
|
|
1 |
from fastapi import APIRouter, HTTPException, status, BackgroundTasks, UploadFile, Query
|
2 |
from .Schema import GeneratorRequest
|
3 |
from .utils.GroqInstruct import chatbot, VideoOutput
|
4 |
+
from .utils.HuggingChat import Hugging
|
5 |
from .Story.Story import Story
|
6 |
import asyncio, pprint, json
|
7 |
from tqdm import tqdm
|
|
|
19 |
async def main(request: GeneratorRequest):
|
20 |
topic = request.prompt
|
21 |
renderr = RenderVideo()
|
22 |
+
huggChat = Hugging()
|
23 |
if request.grok:
|
24 |
message = chatbot(Prompt.format(topic=topic))
|
25 |
|
26 |
else:
|
27 |
+
temp = await huggChat.chat(
|
28 |
+
Prompt.format(topic=topic)
|
29 |
+
+ f"Match your response to the following schema: {VideoOutput.model_json_schema()} Make sure to return an instance of the JSON, not the schema itself, and nothing else."
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
30 |
)
|
31 |
+
message = json.loads(temp.split("```json")[1].split("```")[0].strip())
|
32 |
generated_story = Story.from_dict(message["scenes"])
|
33 |
|
34 |
print("Generated Story ✅")
|