Update app.py
Browse files
app.py
CHANGED
@@ -1,113 +1,37 @@
|
|
1 |
-
from flask import Flask, render_template, request, jsonify
|
2 |
-
from duckduckgo_search import DDGS
|
3 |
-
|
4 |
-
app = Flask(__name__)
|
5 |
-
app.secret_key = 'your-secret-key-here' # Change this to a secure secret key
|
6 |
-
|
7 |
-
STORY_PROMPT = ""
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
</chapter_requirements>
|
39 |
-
|
40 |
-
<continuation_logic>
|
41 |
-
IF {$PREVIOUS_CHAPTER} is provided:
|
42 |
-
- Carefully analyze previous chapter's narrative context
|
43 |
-
- Identify unresolved plot points
|
44 |
-
- Continue story from last chapter's emotional/narrative state
|
45 |
-
- Ensure narrative consistency
|
46 |
-
- Advance character development
|
47 |
-
- Add new narrative complications
|
48 |
-
|
49 |
-
IF {$PREVIOUS_CHAPTER} is NOT provided:
|
50 |
-
- Start a new story based on the given topic
|
51 |
-
- Establish main characters
|
52 |
-
- Create initial narrative conflict
|
53 |
-
</continuation_logic>
|
54 |
-
|
55 |
-
<language_guidelines>
|
56 |
-
- Simple sentence structures
|
57 |
-
- Accessible vocabulary
|
58 |
-
- 8th-grade reading level
|
59 |
-
- Clear, direct language
|
60 |
-
- Contextual explanations
|
61 |
-
- Teen-friendly communication style
|
62 |
-
</language_guidelines>
|
63 |
-
|
64 |
-
<writing_instructions>
|
65 |
-
1. Quickly establish chapter's narrative purpose
|
66 |
-
2. Create compelling character interactions
|
67 |
-
3. Use dynamic dialogue
|
68 |
-
4. Show internal character emotions
|
69 |
-
5. Incorporate contemporary teen references
|
70 |
-
6. Build suspense for next chapter
|
71 |
-
</writing_instructions>
|
72 |
-
|
73 |
-
<output_format>
|
74 |
-
- Write chapter inside <chapter> tags
|
75 |
-
- Include chapter number in <chapter_number>
|
76 |
-
- Add brief <chapter_summary>
|
77 |
-
- Provide <narrative_hook> for next chapter
|
78 |
-
- Optional <content_warning> for mature themes
|
79 |
-
</output_format>
|
80 |
-
|
81 |
-
BEGIN CHAPTER
|
82 |
-
<topic>{$TOPIC}</topic>
|
83 |
-
<previous_chapter>{$PREVIOUS_CHAPTER}</previous_chapter>"""
|
84 |
-
|
85 |
-
@app.route('/')
|
86 |
-
def home():
|
87 |
-
return render_template('index.html')
|
88 |
-
|
89 |
-
@app.route('/generate', methods=['POST'])
|
90 |
-
def generate_story():
|
91 |
-
topic = request.json.get('topic', '')
|
92 |
-
previous_chapter = request.json.get('previous_chapter', '')
|
93 |
-
chapter_number = request.json.get('chapter_number', 1)
|
94 |
-
|
95 |
-
if not topic:
|
96 |
-
return jsonify({'error': 'Topic is required'}), 400
|
97 |
-
|
98 |
-
try:
|
99 |
-
prompt = STORY_PROMPT.replace('{$TOPIC}', topic)
|
100 |
-
prompt = prompt.replace('{$PREVIOUS_CHAPTER}', previous_chapter if previous_chapter else '')
|
101 |
-
|
102 |
-
with DDGS() as ddgs:
|
103 |
-
response = ddgs.chat(prompt, model='claude-3-haiku')
|
104 |
-
|
105 |
-
return jsonify({
|
106 |
-
'story': response,
|
107 |
-
'chapter_number': chapter_number
|
108 |
-
})
|
109 |
-
except Exception as e:
|
110 |
-
return jsonify({'error': str(e)}), 500
|
111 |
-
|
112 |
-
if __name__ == '__main__':
|
113 |
-
app.run(debug=True)
|
|
|
1 |
+
from flask import Flask, render_template, request, jsonify
|
2 |
+
from duckduckgo_search import DDGS
|
3 |
+
import os
|
4 |
+
app = Flask(__name__)
|
5 |
+
app.secret_key = 'your-secret-key-here' # Change this to a secure secret key
|
6 |
+
|
7 |
+
STORY_PROMPT = os.getenv("PROMPT")
|
8 |
+
|
9 |
+
@app.route('/')
|
10 |
+
def home():
|
11 |
+
return render_template('index.html')
|
12 |
+
|
13 |
+
@app.route('/generate', methods=['POST'])
|
14 |
+
def generate_story():
|
15 |
+
topic = request.json.get('topic', '')
|
16 |
+
previous_chapter = request.json.get('previous_chapter', '')
|
17 |
+
chapter_number = request.json.get('chapter_number', 1)
|
18 |
+
|
19 |
+
if not topic:
|
20 |
+
return jsonify({'error': 'Topic is required'}), 400
|
21 |
+
|
22 |
+
try:
|
23 |
+
prompt = STORY_PROMPT.replace('{$TOPIC}', topic)
|
24 |
+
prompt = prompt.replace('{$PREVIOUS_CHAPTER}', previous_chapter if previous_chapter else '')
|
25 |
+
|
26 |
+
with DDGS() as ddgs:
|
27 |
+
response = ddgs.chat(prompt, model='claude-3-haiku')
|
28 |
+
|
29 |
+
return jsonify({
|
30 |
+
'story': response,
|
31 |
+
'chapter_number': chapter_number
|
32 |
+
})
|
33 |
+
except Exception as e:
|
34 |
+
return jsonify({'error': str(e)}), 500
|
35 |
+
|
36 |
+
if __name__ == '__main__':
|
37 |
+
app.run(host='0.0.0.0', port=7860)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|