Update app.py
Browse files
app.py
CHANGED
@@ -1,200 +1,200 @@
|
|
1 |
-
import gradio as gr
|
2 |
-
import markdown as md
|
3 |
-
import yaml
|
4 |
-
from ContentGeneratorAgent import run_crew_cga, set_model, llm_models
|
5 |
-
from GameBuilderAgent import run_crew_game
|
6 |
-
from MarketingPostGeneratorAgent import run_crew_mpga
|
7 |
-
import base64
|
8 |
-
|
9 |
-
def toggle_serper_input(choice):
|
10 |
-
return gr.Textbox(visible=(choice == "Yes"))
|
11 |
-
|
12 |
-
def update_game_instructions(example_key):
|
13 |
-
# Load the game design examples from the YAML file
|
14 |
-
with open('gamedesign.yaml', 'r', encoding='utf-8') as f:
|
15 |
-
examples = yaml.safe_load(f)
|
16 |
-
return examples.get(example_key, "")
|
17 |
-
|
18 |
-
def encode_image(image_path):
|
19 |
-
with open(image_path, "rb") as image_file:
|
20 |
-
return base64.b64encode(image_file.read()).decode('utf-8')
|
21 |
-
|
22 |
-
# Encode the images
|
23 |
-
github_logo_encoded = encode_image("Images/github-logo.png")
|
24 |
-
linkedin_logo_encoded = encode_image("Images/linkedin-logo.png")
|
25 |
-
website_logo_encoded = encode_image("Images/ai-logo.png")
|
26 |
-
|
27 |
-
# UI Setup
|
28 |
-
with gr.Blocks(theme=gr.themes.Soft(font=[gr.themes.GoogleFont("Roboto Mono")]),
|
29 |
-
css='footer {visibility: hidden}') as demo:
|
30 |
-
gr.Markdown("# AI Agents π€π΅π»")
|
31 |
-
|
32 |
-
with gr.Tabs():
|
33 |
-
with gr.TabItem("Intro"):
|
34 |
-
gr.Markdown(md.description)
|
35 |
-
# Tab for SEO Content Generator Agent
|
36 |
-
with gr.TabItem("SEO Content Agent"):
|
37 |
-
with gr.Accordion("π Description:", open=False):
|
38 |
-
gr.Markdown(md.seo_content)
|
39 |
-
with gr.Accordion("How to get GEMINI API KEY", open=False):
|
40 |
-
gr.Markdown(md.gemini_api_key)
|
41 |
-
with gr.Accordion("How to get SERPER API KEY", open=False):
|
42 |
-
gr.Markdown(md.serper_api_key)
|
43 |
-
with gr.Row():
|
44 |
-
with gr.Column(scale=1):
|
45 |
-
model_dropdown = gr.Dropdown(
|
46 |
-
llm_models,
|
47 |
-
label="1. Select AI Model",
|
48 |
-
value=llm_models[0]
|
49 |
-
)
|
50 |
-
gemini_key = gr.Textbox(
|
51 |
-
label="2. Enter Gemini API Key",
|
52 |
-
type="password",
|
53 |
-
placeholder="Paste your Gemini API key here..."
|
54 |
-
)
|
55 |
-
search_toggle = gr.Radio(
|
56 |
-
["Yes", "No"],
|
57 |
-
label="3. Enable Online Search?",
|
58 |
-
value="No"
|
59 |
-
)
|
60 |
-
serper_key = gr.Textbox(
|
61 |
-
label="4. Enter Serper API Key",
|
62 |
-
type="password",
|
63 |
-
visible=False,
|
64 |
-
placeholder="Paste your Serper API key if enabled..."
|
65 |
-
)
|
66 |
-
topic_input = gr.Textbox(
|
67 |
-
label="5. Enter Content Topic",
|
68 |
-
placeholder="Enter your article topic here..."
|
69 |
-
)
|
70 |
-
run_btn = gr.Button("Generate Content", variant="primary")
|
71 |
-
with gr.Column(scale=3):
|
72 |
-
output = gr.Markdown(
|
73 |
-
label="Generated Content",
|
74 |
-
value="Your content will appear here..."
|
75 |
-
)
|
76 |
-
with gr.Accordion("Process Logs", open=True):
|
77 |
-
logs = gr.Markdown()
|
78 |
-
|
79 |
-
# Event handlers for SEO Content Generator
|
80 |
-
model_dropdown.change(set_model, model_dropdown)
|
81 |
-
search_toggle.change(
|
82 |
-
toggle_serper_input,
|
83 |
-
inputs=search_toggle,
|
84 |
-
outputs=serper_key
|
85 |
-
)
|
86 |
-
run_btn.click(
|
87 |
-
run_crew_cga,
|
88 |
-
inputs=[gemini_key, search_toggle, serper_key, topic_input],
|
89 |
-
outputs=[output, logs],
|
90 |
-
show_progress="full"
|
91 |
-
)
|
92 |
-
|
93 |
-
# Tab for Game Dev Agent
|
94 |
-
with gr.TabItem("Game Dev Agent"):
|
95 |
-
with gr.Accordion('π Description:', open=True):
|
96 |
-
gr.Markdown(md.game_dev)
|
97 |
-
with gr.Accordion("How to get GEMINI API KEY", open=False):
|
98 |
-
gr.Markdown(md.gemini_api_key)
|
99 |
-
with gr.Row():
|
100 |
-
with gr.Column(scale=1):
|
101 |
-
game_model_dropdown = gr.Dropdown(
|
102 |
-
llm_models,
|
103 |
-
label="1. Select AI Model",
|
104 |
-
value=llm_models[0]
|
105 |
-
)
|
106 |
-
game_gemini_key = gr.Textbox(
|
107 |
-
label="2. Enter Gemini API Key",
|
108 |
-
type="password",
|
109 |
-
placeholder="Paste your Gemini API key here..."
|
110 |
-
)
|
111 |
-
game_example_dropdown = gr.Dropdown(
|
112 |
-
choices=["pacman", "pacman2", "snake", "space_invaders", "Tetris", "Frogger", "Chess", "Go", "Reversi"],
|
113 |
-
label="3. Select Example",
|
114 |
-
value="example1_pacman"
|
115 |
-
)
|
116 |
-
game_load_example_btn = gr.Button("Load Example", variant="secondary")
|
117 |
-
|
118 |
-
game_instructions = gr.Textbox(
|
119 |
-
label="4. Enter Game Design Instructions",
|
120 |
-
placeholder="Enter your game design instructions here...",
|
121 |
-
lines=5
|
122 |
-
)
|
123 |
-
game_run_btn = gr.Button("Generate Game Code", variant="primary")
|
124 |
-
with gr.Column(scale=3):
|
125 |
-
game_output = gr.Markdown(
|
126 |
-
label="Generated Game Code",
|
127 |
-
value="Your game code will appear here..."
|
128 |
-
)
|
129 |
-
with gr.Accordion("Process Logs", open=False):
|
130 |
-
game_logs = gr.Markdown()
|
131 |
-
|
132 |
-
# Event handlers for Game Dev Agent
|
133 |
-
game_model_dropdown.change(set_model, game_model_dropdown)
|
134 |
-
game_load_example_btn.click(
|
135 |
-
update_game_instructions,
|
136 |
-
inputs=[game_example_dropdown],
|
137 |
-
outputs=[game_instructions]
|
138 |
-
)
|
139 |
-
game_run_btn.click(
|
140 |
-
run_crew_game,
|
141 |
-
inputs=[game_gemini_key, game_instructions],
|
142 |
-
outputs=[game_output, game_logs],
|
143 |
-
show_progress="full"
|
144 |
-
)
|
145 |
-
|
146 |
-
# Tab for Marketing Posts Generator Agent
|
147 |
-
with gr.TabItem("Marketing Posts Generator Agent"):
|
148 |
-
with gr.Accordion("How to get GEMINI API KEY", open=False):
|
149 |
-
gr.Markdown(md.gemini_api_key)
|
150 |
-
with gr.Accordion("How to get SERPER API KEY", open=False):
|
151 |
-
gr.Markdown(md.serper_api_key)
|
152 |
-
with gr.Row():
|
153 |
-
with gr.Column(scale=1):
|
154 |
-
mpga_model_dropdown = gr.Dropdown(
|
155 |
-
llm_models,
|
156 |
-
label="1. Select AI Model",
|
157 |
-
value=llm_models[0]
|
158 |
-
)
|
159 |
-
mpga_gemini_key = gr.Textbox(
|
160 |
-
label="2. Enter Gemini API Key",
|
161 |
-
type="password",
|
162 |
-
placeholder="Paste your Gemini API key here..."
|
163 |
-
)
|
164 |
-
mpga_serper_key = gr.Textbox(
|
165 |
-
label="3. Enter Serper API Key",
|
166 |
-
type="password",
|
167 |
-
placeholder="Paste your Serper API key here..."
|
168 |
-
)
|
169 |
-
customer_domain = gr.Textbox(
|
170 |
-
label="4. Enter Customer Domain",
|
171 |
-
placeholder="Enter the customer domain here..."
|
172 |
-
)
|
173 |
-
project_description = gr.Textbox(
|
174 |
-
label="5. Enter Project Description",
|
175 |
-
placeholder="Enter the project description here..."
|
176 |
-
)
|
177 |
-
mpga_run_btn = gr.Button("Generate Marketing Posts", variant="primary")
|
178 |
-
with gr.Column(scale=3):
|
179 |
-
mpga_output = gr.Markdown(
|
180 |
-
label="Generated Marketing Posts",
|
181 |
-
value="Your marketing posts will appear here..."
|
182 |
-
)
|
183 |
-
with gr.Accordion("Process Logs", open=False):
|
184 |
-
mpga_logs = gr.Markdown()
|
185 |
-
|
186 |
-
# Event handlers for Marketing Posts Generator Agent
|
187 |
-
mpga_model_dropdown.change(set_model, mpga_model_dropdown)
|
188 |
-
# mpga_run_btn.click(
|
189 |
-
# run_crew_mpga,
|
190 |
-
# inputs=[mpga_gemini_key, mpga_serper_key, {
|
191 |
-
# "customer_domain": customer_domain,
|
192 |
-
# "project_description": project_description
|
193 |
-
# }],
|
194 |
-
# outputs=[mpga_output, mpga_logs],
|
195 |
-
# show_progress="full"
|
196 |
-
# )
|
197 |
-
gr.HTML(md.footer.format(github_logo_encoded, linkedin_logo_encoded, website_logo_encoded))
|
198 |
-
|
199 |
-
if __name__ == "__main__":
|
200 |
-
demo.launch()
|
|
|
1 |
+
import gradio as gr
|
2 |
+
import markdown as md
|
3 |
+
import yaml
|
4 |
+
from ContentGeneratorAgent import run_crew_cga, set_model, llm_models
|
5 |
+
from GameBuilderAgent import run_crew_game
|
6 |
+
from MarketingPostGeneratorAgent import run_crew_mpga
|
7 |
+
import base64
|
8 |
+
|
9 |
+
def toggle_serper_input(choice):
|
10 |
+
return gr.Textbox(visible=(choice == "Yes"))
|
11 |
+
|
12 |
+
def update_game_instructions(example_key):
|
13 |
+
# Load the game design examples from the YAML file
|
14 |
+
with open('gamedesign.yaml', 'r', encoding='utf-8') as f:
|
15 |
+
examples = yaml.safe_load(f)
|
16 |
+
return examples.get(example_key, "")
|
17 |
+
|
18 |
+
def encode_image(image_path):
|
19 |
+
with open(image_path, "rb") as image_file:
|
20 |
+
return base64.b64encode(image_file.read()).decode('utf-8')
|
21 |
+
|
22 |
+
# Encode the images
|
23 |
+
github_logo_encoded = encode_image("Images/github-logo.png")
|
24 |
+
linkedin_logo_encoded = encode_image("Images/linkedin-logo.png")
|
25 |
+
website_logo_encoded = encode_image("Images/ai-logo.png")
|
26 |
+
|
27 |
+
# UI Setup
|
28 |
+
with gr.Blocks(theme=gr.themes.Soft(font=[gr.themes.GoogleFont("Roboto Mono")]),
|
29 |
+
css='footer {visibility: hidden}') as demo:
|
30 |
+
gr.Markdown("# AI Agents π€π΅π»")
|
31 |
+
|
32 |
+
with gr.Tabs():
|
33 |
+
with gr.TabItem("Intro"):
|
34 |
+
gr.Markdown(md.description)
|
35 |
+
# Tab for SEO Content Generator Agent
|
36 |
+
with gr.TabItem("SEO Content Agent"):
|
37 |
+
with gr.Accordion("π Description:", open=False):
|
38 |
+
gr.Markdown(md.seo_content)
|
39 |
+
with gr.Accordion("How to get GEMINI API KEY", open=False):
|
40 |
+
gr.Markdown(md.gemini_api_key)
|
41 |
+
with gr.Accordion("How to get SERPER API KEY", open=False):
|
42 |
+
gr.Markdown(md.serper_api_key)
|
43 |
+
with gr.Row():
|
44 |
+
with gr.Column(scale=1):
|
45 |
+
model_dropdown = gr.Dropdown(
|
46 |
+
llm_models,
|
47 |
+
label="1. Select AI Model",
|
48 |
+
value=llm_models[0]
|
49 |
+
)
|
50 |
+
gemini_key = gr.Textbox(
|
51 |
+
label="2. Enter Gemini API Key",
|
52 |
+
type="password",
|
53 |
+
placeholder="Paste your Gemini API key here..."
|
54 |
+
)
|
55 |
+
search_toggle = gr.Radio(
|
56 |
+
["Yes", "No"],
|
57 |
+
label="3. Enable Online Search?",
|
58 |
+
value="No"
|
59 |
+
)
|
60 |
+
serper_key = gr.Textbox(
|
61 |
+
label="4. Enter Serper API Key",
|
62 |
+
type="password",
|
63 |
+
visible=False,
|
64 |
+
placeholder="Paste your Serper API key if enabled..."
|
65 |
+
)
|
66 |
+
topic_input = gr.Textbox(
|
67 |
+
label="5. Enter Content Topic",
|
68 |
+
placeholder="Enter your article topic here..."
|
69 |
+
)
|
70 |
+
run_btn = gr.Button("Generate Content", variant="primary")
|
71 |
+
with gr.Column(scale=3):
|
72 |
+
output = gr.Markdown(
|
73 |
+
label="Generated Content",
|
74 |
+
value="Your content will appear here..."
|
75 |
+
)
|
76 |
+
with gr.Accordion("Process Logs", open=True):
|
77 |
+
logs = gr.Markdown()
|
78 |
+
|
79 |
+
# Event handlers for SEO Content Generator
|
80 |
+
model_dropdown.change(set_model, model_dropdown)
|
81 |
+
search_toggle.change(
|
82 |
+
toggle_serper_input,
|
83 |
+
inputs=search_toggle,
|
84 |
+
outputs=serper_key
|
85 |
+
)
|
86 |
+
run_btn.click(
|
87 |
+
run_crew_cga,
|
88 |
+
inputs=[gemini_key, search_toggle, serper_key, topic_input],
|
89 |
+
outputs=[output, logs],
|
90 |
+
show_progress="full"
|
91 |
+
)
|
92 |
+
|
93 |
+
# Tab for Game Dev Agent
|
94 |
+
with gr.TabItem("Game Dev Agent"):
|
95 |
+
with gr.Accordion('π Description:', open=True):
|
96 |
+
gr.Markdown(md.game_dev)
|
97 |
+
with gr.Accordion("How to get GEMINI API KEY", open=False):
|
98 |
+
gr.Markdown(md.gemini_api_key)
|
99 |
+
with gr.Row():
|
100 |
+
with gr.Column(scale=1):
|
101 |
+
game_model_dropdown = gr.Dropdown(
|
102 |
+
llm_models,
|
103 |
+
label="1. Select AI Model",
|
104 |
+
value=llm_models[0]
|
105 |
+
)
|
106 |
+
game_gemini_key = gr.Textbox(
|
107 |
+
label="2. Enter Gemini API Key",
|
108 |
+
type="password",
|
109 |
+
placeholder="Paste your Gemini API key here..."
|
110 |
+
)
|
111 |
+
game_example_dropdown = gr.Dropdown(
|
112 |
+
choices=["pacman", "pacman2", "snake", "space_invaders", "Tetris", "Frogger", "Chess", "Go", "Reversi"],
|
113 |
+
label="3. Select Example",
|
114 |
+
value="example1_pacman"
|
115 |
+
)
|
116 |
+
game_load_example_btn = gr.Button("Load Example", variant="secondary")
|
117 |
+
|
118 |
+
game_instructions = gr.Textbox(
|
119 |
+
label="4. Enter Game Design Instructions",
|
120 |
+
placeholder="Enter your game design instructions here...",
|
121 |
+
lines=5
|
122 |
+
)
|
123 |
+
game_run_btn = gr.Button("Generate Game Code", variant="primary")
|
124 |
+
with gr.Column(scale=3):
|
125 |
+
game_output = gr.Markdown(
|
126 |
+
label="Generated Game Code",
|
127 |
+
value="Your game code will appear here..."
|
128 |
+
)
|
129 |
+
with gr.Accordion("Process Logs", open=False):
|
130 |
+
game_logs = gr.Markdown()
|
131 |
+
|
132 |
+
# Event handlers for Game Dev Agent
|
133 |
+
game_model_dropdown.change(set_model, game_model_dropdown)
|
134 |
+
game_load_example_btn.click(
|
135 |
+
update_game_instructions,
|
136 |
+
inputs=[game_example_dropdown],
|
137 |
+
outputs=[game_instructions]
|
138 |
+
)
|
139 |
+
game_run_btn.click(
|
140 |
+
run_crew_game,
|
141 |
+
inputs=[game_gemini_key, game_instructions],
|
142 |
+
outputs=[game_output, game_logs],
|
143 |
+
show_progress="full"
|
144 |
+
)
|
145 |
+
|
146 |
+
# Tab for Marketing Posts Generator Agent
|
147 |
+
with gr.TabItem("Marketing Posts Generator Agent"):
|
148 |
+
with gr.Accordion("How to get GEMINI API KEY", open=False):
|
149 |
+
gr.Markdown(md.gemini_api_key)
|
150 |
+
with gr.Accordion("How to get SERPER API KEY", open=False):
|
151 |
+
gr.Markdown(md.serper_api_key)
|
152 |
+
with gr.Row():
|
153 |
+
with gr.Column(scale=1):
|
154 |
+
mpga_model_dropdown = gr.Dropdown(
|
155 |
+
llm_models,
|
156 |
+
label="1. Select AI Model",
|
157 |
+
value=llm_models[0]
|
158 |
+
)
|
159 |
+
mpga_gemini_key = gr.Textbox(
|
160 |
+
label="2. Enter Gemini API Key",
|
161 |
+
type="password",
|
162 |
+
placeholder="Paste your Gemini API key here..."
|
163 |
+
)
|
164 |
+
mpga_serper_key = gr.Textbox(
|
165 |
+
label="3. Enter Serper API Key",
|
166 |
+
type="password",
|
167 |
+
placeholder="Paste your Serper API key here..."
|
168 |
+
)
|
169 |
+
customer_domain = gr.Textbox(
|
170 |
+
label="4. Enter Customer Domain",
|
171 |
+
placeholder="Enter the customer domain here..."
|
172 |
+
)
|
173 |
+
project_description = gr.Textbox(
|
174 |
+
label="5. Enter Project Description",
|
175 |
+
placeholder="Enter the project description here..."
|
176 |
+
)
|
177 |
+
mpga_run_btn = gr.Button("Generate Marketing Posts", variant="primary")
|
178 |
+
with gr.Column(scale=3):
|
179 |
+
mpga_output = gr.Markdown(
|
180 |
+
label="Generated Marketing Posts",
|
181 |
+
value="Your marketing posts will appear here..."
|
182 |
+
)
|
183 |
+
with gr.Accordion("Process Logs", open=False):
|
184 |
+
mpga_logs = gr.Markdown()
|
185 |
+
|
186 |
+
# Event handlers for Marketing Posts Generator Agent
|
187 |
+
mpga_model_dropdown.change(set_model, mpga_model_dropdown)
|
188 |
+
# mpga_run_btn.click(
|
189 |
+
# run_crew_mpga,
|
190 |
+
# inputs=[mpga_gemini_key, mpga_serper_key, {
|
191 |
+
# "customer_domain": customer_domain,
|
192 |
+
# "project_description": project_description
|
193 |
+
# }],
|
194 |
+
# outputs=[mpga_output, mpga_logs],
|
195 |
+
# show_progress="full"
|
196 |
+
# )
|
197 |
+
gr.HTML(md.footer.format(github_logo_encoded, linkedin_logo_encoded, website_logo_encoded))
|
198 |
+
|
199 |
+
if __name__ == "__main__":
|
200 |
+
demo.launch()
|