Spaces:
Sleeping
Sleeping
updated
Browse files
app.py
CHANGED
@@ -45,25 +45,25 @@ def load_model(
|
|
45 |
# n_ctx=1024
|
46 |
# )
|
47 |
|
48 |
-
model = LlamaCpp(
|
49 |
-
model_path=final_model_path,
|
50 |
-
temperature=0.3,
|
51 |
-
max_tokens=2000,
|
52 |
-
top_p=1,
|
53 |
-
n_ctx=1024,
|
54 |
-
callback_manager=callback_manager,
|
55 |
-
verbose=True,
|
56 |
-
)
|
57 |
-
|
58 |
-
# model = Llama(
|
59 |
# model_path=final_model_path,
|
60 |
# temperature=0.3,
|
61 |
# max_tokens=2000,
|
|
|
62 |
# n_ctx=1024,
|
63 |
-
#
|
64 |
-
#
|
65 |
# )
|
66 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
67 |
|
68 |
print("Model loaded!")
|
69 |
return model
|
@@ -72,6 +72,8 @@ def load_model(
|
|
72 |
llm = load_model()
|
73 |
|
74 |
|
|
|
|
|
75 |
# Create a prompt template
|
76 |
# system = """You are a helpful and creative assistant that specializes in generating engaging and imaginative stories for kids.
|
77 |
# Based on the user's provided mood, preferred story type, theme, age, and desired story length of 500-600 words, create a unique and captivating story.
|
@@ -97,19 +99,28 @@ async def generate_story(story_request: StoryRequest):
|
|
97 |
- **Theme:** {story_request.theme}
|
98 |
- **Details Provided:** {story_request.txt}
|
99 |
"""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
100 |
|
101 |
-
|
|
|
|
|
|
|
|
|
|
|
102 |
|
103 |
-
# Create the LLMChain
|
104 |
-
# chain = LLMChain(llm=llm, prompt=prompt_template)
|
105 |
-
chain = llm | prompt_template
|
106 |
|
107 |
-
# try:
|
108 |
-
# response = chain.invoke(final_prompt)
|
109 |
-
# return {"story": response}
|
110 |
-
# except Exception as e:
|
111 |
-
# raise HTTPException(status_code=500, detail=str(e))
|
112 |
-
response = chain.invoke(final_prompt)
|
113 |
|
114 |
if not response:
|
115 |
raise HTTPException(status_code=500, detail="Failed to generate the story")
|
|
|
45 |
# n_ctx=1024
|
46 |
# )
|
47 |
|
48 |
+
# model = LlamaCpp(
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
49 |
# model_path=final_model_path,
|
50 |
# temperature=0.3,
|
51 |
# max_tokens=2000,
|
52 |
+
# top_p=1,
|
53 |
# n_ctx=1024,
|
54 |
+
# callback_manager=callback_manager,
|
55 |
+
# verbose=True,
|
56 |
# )
|
57 |
|
58 |
+
model = Llama(
|
59 |
+
model_path=final_model_path,
|
60 |
+
temperature=0.3,
|
61 |
+
max_tokens=2000,
|
62 |
+
n_ctx=1024,
|
63 |
+
# n_threads=8,
|
64 |
+
echo=False
|
65 |
+
)
|
66 |
+
|
67 |
|
68 |
print("Model loaded!")
|
69 |
return model
|
|
|
72 |
llm = load_model()
|
73 |
|
74 |
|
75 |
+
|
76 |
+
|
77 |
# Create a prompt template
|
78 |
# system = """You are a helpful and creative assistant that specializes in generating engaging and imaginative stories for kids.
|
79 |
# Based on the user's provided mood, preferred story type, theme, age, and desired story length of 500-600 words, create a unique and captivating story.
|
|
|
99 |
- **Theme:** {story_request.theme}
|
100 |
- **Details Provided:** {story_request.txt}
|
101 |
"""
|
102 |
+
|
103 |
+
response = llm.create_chat_completion(
|
104 |
+
messages = [
|
105 |
+
{"role": "system", "content": system},
|
106 |
+
{"role": "user","content": story}
|
107 |
+
]
|
108 |
+
)
|
109 |
+
|
110 |
+
# final_prompt = prompt_template.format(text=story)
|
111 |
+
|
112 |
+
# # Create the LLMChain
|
113 |
+
# # chain = LLMChain(llm=llm, prompt=prompt_template)
|
114 |
+
# chain = llm | prompt_template
|
115 |
|
116 |
+
# # try:
|
117 |
+
# # response = chain.invoke(final_prompt)
|
118 |
+
# # return {"story": response}
|
119 |
+
# # except Exception as e:
|
120 |
+
# # raise HTTPException(status_code=500, detail=str(e))
|
121 |
+
# response = chain.invoke(final_prompt)
|
122 |
|
|
|
|
|
|
|
123 |
|
|
|
|
|
|
|
|
|
|
|
|
|
124 |
|
125 |
if not response:
|
126 |
raise HTTPException(status_code=500, detail="Failed to generate the story")
|