Advertisement
Guest User

Broken Flask

a guest
Aug 11th, 2023
258
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.03 KB | None | 0 0
  1. <!-- templates/index.html -->
  2. <!DOCTYPE html>
  3. <html>
  4.  
  5. <head>
  6. <title>CK3 Faith Maker</title>
  7. <link rel="stylesheet" href="{{ url_for('static', filename='style.css') }}">
  8. </head>
  9.  
  10. <body>
  11. <h1>CK3 Faith Maker</h1>
  12. <form method="POST">
  13. <label for="religion_name">Enter Religion Name:</label><br>
  14. <input type="text" name="religion_name"><br><br>
  15. <p>Select three tenets:</p>
  16. {% for tenet in available_tenets %}
  17. <input type="checkbox" name="selected_tenets" value="{{ tenet }}">{{ tenet }}<br>
  18. {% endfor %}
  19. <!-- ... (previous input fields) -->
  20. <input type="submit" value="Generate Religion">
  21. </form>
  22. <h2>Generated Religion:</h2>
  23. <p>{{ generated_religion }}</p>
  24. </body>
  25.  
  26. </html>
  27.  
  28.  
  29. <!-- app.py -->
  30. from flask import Flask, render_template, request
  31. import openai
  32. from config import OPENAI_API_KEY
  33. # OPENAI_API_KEY is my API key in the config.py file (same level as app.py)
  34. # OPENAI_API_KEY = "sk-[otherstuffhere]"
  35.  
  36. app = Flask(__name__)
  37. openai.api_key = OPENAI_API_KEY
  38.  
  39. # Define the available tenets
  40. available_tenets = [
  41. "Polyamory", "Pursuit of Power", "Religious Law", "Ritual Cannibalism", "Ritual Celebrations",
  42. "Sacred Lies", "Sanctity of Nature", "Tax Nonbelievers", "Unrelenting Faith", "Vows of Poverty",
  43. "Adorcism", "Alexandrian Catechism", "Ancestor Worship", "Aniconism", "Armed Pilgrimages",
  44. "Auspicious Birthright", "Bhakti", "Dharmic Pacifism", "Hedonistic", "Human Sacrifice",
  45. "Inner Journey", "Pacifism", "Pastoral Isolation", "Reincarnation", "Rite", "Ritual Hospitality",
  46. "Ritual Suicide", "Sacred Childbirth", "Sacrificial Ceremonies", "Sanctioned False Conversions",
  47. "Sky Burials", "Struggle and Submission", "Sun Worship", "Warmonger", "Gruesome Festivals",
  48. "Christian Syncretism", "Islamic Syncretism", "Jewish Syncretism", "Eastern Syncretism",
  49. "Syncretic Folk Traditions"
  50. ]
  51.  
  52. # Function to find the closest matching tenets based on user input
  53. def find_relevant_tenets(user_input):
  54. relevant_tenets = []
  55. user_keywords = user_input.split() # Split user input into keywords
  56.  
  57. # Dictionary to store tenets and their relevance scores
  58. tenet_scores = {}
  59.  
  60. # Calculate relevance scores for each tenet based on keyword matching
  61. for tenet in available_tenets:
  62. tenet_keywords = tenet.lower().split() # Split tenet into keywords
  63. relevance_score = sum(keyword in tenet_keywords for keyword in user_keywords)
  64. tenet_scores[tenet] = relevance_score
  65.  
  66. # Select the top three relevant tenets
  67. relevant_tenets = sorted(tenet_scores, key=lambda x: tenet_scores[x], reverse=True)[:3]
  68.  
  69. return relevant_tenets
  70.  
  71. @app.route('/', methods=['GET', 'POST'])
  72. def index():
  73. generated_religion = ""
  74.  
  75. if request.method == 'POST':
  76. religion_name = request.form['religion_name']
  77.  
  78. user_input = religion_name.lower() # Convert user input to lowercase for comparison
  79. selected_tenets = find_relevant_tenets(user_input)
  80.  
  81. # Create a list of doctrines and tenets based on user's religion input
  82. main_doctrines = {
  83. "Views on Gender": ["Male Dominated", "Equal", "Female Dominated"],
  84. "Religious Attitude": ["Fundamentalist", "Righteous", "Pluralist"],
  85. "Clerical Tradition": ["Theocratic", "Lay Clergy"],
  86. "Head of Faith": ["None", "Spiritual", "Temporal"],
  87. "Pilgrimage Attitude": ["Forbidden", "Encouraged", "Mandatory"],
  88. # Add more main doctrines...
  89. }
  90.  
  91.  
  92. marriage_doctrines = {
  93. "Marriage Type": ["mono", "poly", "Consorts/Concubines"],
  94. "Divorced": ["disallowed", "Must be Approved", "Always allowed"],
  95. "Bastardy": ["None", "Legitimization", "No Legitimization"],
  96. "Consanguinity": ["Close-kin Taboo", "Cousin", "Avunculate", "Unrestricted"],
  97. # Add more marriage doctrines...
  98. }
  99.  
  100. crime_doctrines = {
  101. "Same Sex": ["Crime", "Shunned", "Accepted"],
  102. "Male Adultery": ["Crime", "Shunned", "Accepted"],
  103. "Female Adultery": ["Crime", "Shunned", "Accepted"],
  104. "Deviancy": ["Crime", "Shunned", "Accepted"],
  105. "Witch": ["Crime", "Shunned", "Accepted", "Virtuous"],
  106. "Kinslaying": ["Dynastic is Crime", "Familial is Crime", "Close-kin is Crime", "Shunned Accepted"],
  107. # Add more crime doctrines...
  108. }
  109.  
  110.  
  111. clerical_doctrines = {
  112. "Clerical Function": ["control", "alms and pacification", "recruitment"],
  113. "Clerical Gender": ["only men", "either", "only women"],
  114. "Clerical Marriage": ["allowed", "disallowed"],
  115. "Clerical Appointment": ["Temporal+Revocable", "Spiritual+Revocable", "Temporal+for Life", "Spiritual+for Life"],
  116. # Add more clerical doctrines...
  117. }
  118.  
  119. # Construct the prompt
  120. prompt = f"Generate a CK3 religion based on the following beliefs:\n"
  121. prompt += f"Religion Name: {religion_name}\n"
  122. prompt += f"Selected Tenets: {', '.join(selected_tenets)}\n"
  123. for doctrine, options in main_doctrines.items():
  124. prompt += f"{doctrine}: {options}\n"
  125. for doctrine, options in marriage_doctrines.items():
  126. prompt += f"{doctrine}: {options}\n"
  127. for doctrine, options in crime_doctrines.items():
  128. prompt += f"{doctrine}: {options}\n"
  129. for doctrine, options in clerical_doctrines.items():
  130. prompt += f"{doctrine}: {options}\n"
  131.  
  132. # Call OpenAI API to generate religion based on user input
  133. response = openai.Completion.create(
  134. engine="text-davinci-003", # Choose the appropriate engine
  135. prompt=prompt,
  136. max_tokens=300 # Adjust as needed
  137. )
  138. generated_religion = response.choices[0].text
  139.  
  140. return render_template('index.html', generated_religion=generated_religion)
  141.  
  142. if __name__ == '__main__':
  143. app.run(debug=True)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement