CodeNine commited on
Commit
3274a84
·
verified ·
1 Parent(s): 962ef6a

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +35 -0
app.py ADDED
@@ -0,0 +1,35 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import openai
3
+ import os
4
+
5
+ # Get your OpenAI API key (store as secret in Hugging Face later)
6
+ openai.api_key = os.getenv("OPENAI_API_KEY")
7
+
8
+ st.set_page_config(page_title="AI World Builder Game", page_icon="🌍")
9
+ st.title("🌍 AI-Generated Fantasy World Explorer")
10
+
11
+ st.markdown("Explore unique regions generated by AI. Every click reveals a new civilization, its culture, and quests!")
12
+
13
+ if st.button("🧭 Explore New Region"):
14
+ with st.spinner("Generating region..."):
15
+ prompt = """
16
+ Create a fantasy world region. Include:
17
+ 1. Name of the region
18
+ 2. Civilization name and a short backstory
19
+ 3. Details about the culture (food, clothing, beliefs)
20
+ 4. One interesting quest in that area
21
+ Format nicely for display.
22
+ """
23
+
24
+ try:
25
+ response = openai.ChatCompletion.create(
26
+ model="gpt-4o",
27
+ messages=[{"role": "user", "content": prompt}],
28
+ temperature=0.8
29
+ )
30
+ story = response.choices[0].message.content
31
+ st.success("New region discovered!")
32
+ st.markdown(f"```markdown\n{story}\n```")
33
+
34
+ except Exception as e:
35
+ st.error(f"Error: {e}")