-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.py
89 lines (71 loc) · 2.45 KB
/
app.py
1
2
3
4
5
6
7
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
from flask import Flask, render_template, request, jsonify
from mira_sdk import MiraClient, Flow
import os
app = Flask(__name__)
client = MiraClient(config={"API_KEY": "sb-b55907818667805d636940340f42d849"})
@app.route('/')
def index():
return render_template('index.html')
@app.route('/about')
def about():
return render_template('about.html')
@app.route('/contact')
def contact():
return render_template('contact.html')
@app.route('/generate_stories', methods=['POST'])
def generate_stories():
tone = request.form.get('tone', '')
genre = request.form.get('genre', '')
topic = request.form.get('topic', '')
input_data = {
"tone": tone,
"genre": genre,
"topic": topic
}
version = "0.1.0"
flow_name = f"@shreyannarula1/story-outline-generator/{version}"
try:
result = client.flow.execute(flow_name, input_data)
outlines = result.get("outlinestory", "").split("\n")
plots = [plot.strip() for plot in outlines if plot.strip()]
while len(plots) < 5:
plots.append(f"Plot {len(plots) + 1}: Additional plot option needed")
plots = plots[:5]
return jsonify({
"status": "success",
"plots": plots,
"tone": tone,
"genre": genre,
"topic": topic
})
except Exception as e:
return jsonify({"status": "error", "message": str(e)})
@app.route('/improve_story', methods=['POST'])
def improve_story():
plot = request.form.get('plot', '')
tone = request.form.get('tone', '')
genre = request.form.get('genre', '')
topic = request.form.get('topic', '')
twist = request.form.get('twist', '')
input_data = {
"plot": plot,
"tone": tone,
"genre": genre,
"topic": topic,
"twist": twist
}
version = "0.1.0"
flow_name = f"@shreyannarula1/story-update-and-improvement-generator/{version}"
try:
result = client.flow.execute(flow_name, input_data)
if isinstance(result, str):
sections = result.split('\n\n')[:5]
result = {f"Section {i+1}": section for i, section in enumerate(sections)}
return jsonify({
"status": "success",
"improved_story": result
})
except Exception as e:
return jsonify({"status": "error", "message": str(e)})
if __name__ == '__main__':
app.run(debug=True)