AmnaHassan commited on
Commit
08d17c7
·
verified ·
1 Parent(s): 545b8c3

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +19 -11
app.py CHANGED
@@ -1,14 +1,22 @@
 
1
  import streamlit as st
2
  import anthropic
 
3
 
4
- # Initialize the Anthropic client
5
- client = anthropic.Anthropic()
 
 
 
 
 
 
6
 
7
  # Define the functions to generate content
8
  def generate_game_environment(environment_description):
9
  message = client.messages.create(
10
  model="claude-3-5-sonnet-20240620",
11
- max_tokens=1000,
12
  temperature=0.7,
13
  system="You are an expert in world-building. Generate a detailed description of a game environment based on the input.",
14
  messages=[
@@ -23,12 +31,12 @@ def generate_game_environment(environment_description):
23
  }
24
  ]
25
  )
26
- return message.content
27
 
28
  def generate_protagonist(protagonist_description):
29
  message = client.messages.create(
30
  model="claude-3-5-sonnet-20240620",
31
- max_tokens=1000,
32
  temperature=0.7,
33
  system="You are an expert in character creation. Generate a detailed description of a game protagonist based on the input.",
34
  messages=[
@@ -43,12 +51,12 @@ def generate_protagonist(protagonist_description):
43
  }
44
  ]
45
  )
46
- return message.content
47
 
48
  def generate_antagonist(antagonist_description):
49
  message = client.messages.create(
50
  model="claude-3-5-sonnet-20240620",
51
- max_tokens=1000,
52
  temperature=0.7,
53
  system="You are an expert in villain creation. Generate a detailed description of a game antagonist based on the input.",
54
  messages=[
@@ -63,7 +71,7 @@ def generate_antagonist(antagonist_description):
63
  }
64
  ]
65
  )
66
- return message.content
67
 
68
  def generate_game_story(environment, protagonist, antagonist):
69
  story_prompt = (f"Create a detailed game story based on the following inputs:\n"
@@ -72,7 +80,7 @@ def generate_game_story(environment, protagonist, antagonist):
72
  f"Antagonist: {antagonist}")
73
  message = client.messages.create(
74
  model="claude-3-5-sonnet-20240620",
75
- max_tokens=1000,
76
  temperature=0.7,
77
  system="You are a master storyteller. Generate a detailed game story based on the inputs provided.",
78
  messages=[
@@ -87,7 +95,7 @@ def generate_game_story(environment, protagonist, antagonist):
87
  }
88
  ]
89
  )
90
- return message.content
91
 
92
  # App Title
93
  st.title("StoryForge")
@@ -108,7 +116,7 @@ with st.sidebar:
108
  antagonist_description = generate_antagonist(antagonist)
109
  game_story = generate_game_story(game_environment, protagonist, antagonist)
110
 
111
- # Display generated content
112
  st.session_state.env_description = env_description
113
  st.session_state.protagonist_description = protagonist_description
114
  st.session_state.antagonist_description = antagonist_description
 
1
+ import os
2
  import streamlit as st
3
  import anthropic
4
+ from dotenv import load_dotenv
5
 
6
+ # Load environment variables from .env file
7
+ load_dotenv()
8
+
9
+ # Retrieve the API key from environment variables
10
+ api_key = os.getenv("Claude_api_key")
11
+
12
+ # Initialize the Anthropic client with the API key
13
+ client = anthropic.Anthropic(api_key=api_key)
14
 
15
  # Define the functions to generate content
16
  def generate_game_environment(environment_description):
17
  message = client.messages.create(
18
  model="claude-3-5-sonnet-20240620",
19
+ max_tokens=150,
20
  temperature=0.7,
21
  system="You are an expert in world-building. Generate a detailed description of a game environment based on the input.",
22
  messages=[
 
31
  }
32
  ]
33
  )
34
+ return message.content[0].text
35
 
36
  def generate_protagonist(protagonist_description):
37
  message = client.messages.create(
38
  model="claude-3-5-sonnet-20240620",
39
+ max_tokens=150,
40
  temperature=0.7,
41
  system="You are an expert in character creation. Generate a detailed description of a game protagonist based on the input.",
42
  messages=[
 
51
  }
52
  ]
53
  )
54
+ return message.content[0].text
55
 
56
  def generate_antagonist(antagonist_description):
57
  message = client.messages.create(
58
  model="claude-3-5-sonnet-20240620",
59
+ max_tokens=150,
60
  temperature=0.7,
61
  system="You are an expert in villain creation. Generate a detailed description of a game antagonist based on the input.",
62
  messages=[
 
71
  }
72
  ]
73
  )
74
+ return message.content[0].text
75
 
76
  def generate_game_story(environment, protagonist, antagonist):
77
  story_prompt = (f"Create a detailed game story based on the following inputs:\n"
 
80
  f"Antagonist: {antagonist}")
81
  message = client.messages.create(
82
  model="claude-3-5-sonnet-20240620",
83
+ max_tokens= 150,
84
  temperature=0.7,
85
  system="You are a master storyteller. Generate a detailed game story based on the inputs provided.",
86
  messages=[
 
95
  }
96
  ]
97
  )
98
+ return message.content[0].text
99
 
100
  # App Title
101
  st.title("StoryForge")
 
116
  antagonist_description = generate_antagonist(antagonist)
117
  game_story = generate_game_story(game_environment, protagonist, antagonist)
118
 
119
+ # Store results in session state
120
  st.session_state.env_description = env_description
121
  st.session_state.protagonist_description = protagonist_description
122
  st.session_state.antagonist_description = antagonist_description