Talha812 commited on
Commit
2d96b96
·
verified ·
1 Parent(s): 08d17c7

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +36 -68
app.py CHANGED
@@ -1,101 +1,69 @@
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=[
23
- {
24
- "role": "user",
25
- "content": [
26
- {
27
- "type": "text",
28
- "text": f"Create a detailed description of a game environment based on this input: {environment_description}"
29
- }
30
- ]
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=[
43
- {
44
- "role": "user",
45
- "content": [
46
- {
47
- "type": "text",
48
- "text": f"Create a detailed description of a game protagonist based on this input: {protagonist_description}"
49
- }
50
- ]
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=[
63
- {
64
- "role": "user",
65
- "content": [
66
- {
67
- "type": "text",
68
- "text": f"Create a detailed description of a game antagonist based on this input: {antagonist_description}"
69
- }
70
- ]
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"
78
  f"Game Environment: {environment}\n"
79
  f"Protagonist: {protagonist}\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=[
87
- {
88
- "role": "user",
89
- "content": [
90
- {
91
- "type": "text",
92
- "text": story_prompt
93
- }
94
- ]
95
- }
96
- ]
97
  )
98
- return message.content[0].text
99
 
100
  # App Title
101
  st.title("StoryForge")
 
1
  import os
2
  import streamlit as st
 
3
  from dotenv import load_dotenv
4
+ from groq import Groq
5
  # Load environment variables from .env file
6
  load_dotenv()
7
 
8
  # Retrieve the API key from environment variables
9
+ api_key = os.getenv("groq_api_key")
10
 
11
  # Initialize the Anthropic client with the API key
12
+ client = Groq(api_key=api_key)
13
 
14
  # Define the functions to generate content
15
  def generate_game_environment(environment_description):
16
+ message = client.chat.completions.create(
 
 
 
 
17
  messages=[
18
+ {
19
+ "role": "user",
20
+ "content": f"You are an expert in world-building. Generate a detailed description of a game environment based on the input. Create a detailed description of a game environment based on this input: {environment_description}",
21
+ }
22
+ ],
23
+ model="llama-3.3-70b-versatile",
 
 
 
 
24
  )
25
+ return message.choices[0].message.content
26
 
27
  def generate_protagonist(protagonist_description):
28
+ message = client.chat.completions.create(
 
 
 
 
29
  messages=[
30
+ {
31
+ "role": "user",
32
+ "content": f"You are an expert in character creation. Generate a detailed description of a game protagonist based on the input. Create a detailed description of a game protagonist based on this input: {protagonist_description}",
33
+ }
34
+ ],
35
+ model="llama-3.3-70b-versatile",
 
 
 
 
36
  )
37
+ return message.choices[0].message.content
38
 
39
  def generate_antagonist(antagonist_description):
40
+ message = client.chat.completions.create(
 
 
 
 
41
  messages=[
42
+ {
43
+ "role": "user",
44
+ "content": f"You are an expert in villain creation. Generate a detailed description of a game antagonist based on the input. Create a detailed description of a game antagonist based on this input: {antagonist_description}.",
45
+ }
46
+ ],
47
+ model="llama-3.3-70b-versatile",
 
 
 
 
48
  )
49
+ return message.choices[0].message.content
50
 
51
  def generate_game_story(environment, protagonist, antagonist):
52
  story_prompt = (f"Create a detailed game story based on the following inputs:\n"
53
  f"Game Environment: {environment}\n"
54
  f"Protagonist: {protagonist}\n"
55
  f"Antagonist: {antagonist}")
56
+
57
+ message = client.chat.completions.create(
 
 
 
58
  messages=[
59
+ {
60
+ "role": "user",
61
+ "content": f"You are a master storyteller. Generate a detailed game story based on the inputs provided.\n {story_prompt}",
62
+ }
63
+ ],
64
+ model="llama-3.3-70b-versatile",
 
 
 
 
65
  )
66
+ return message.choices[0].message.content
67
 
68
  # App Title
69
  st.title("StoryForge")