-
Notifications
You must be signed in to change notification settings - Fork 4.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Create a simple webui with gradio #316
base: main
Are you sure you want to change the base?
Changes from 1 commit
33143c4
922ccf3
cccef57
a9b6d9b
8040782
78e966a
c0d43e7
24a0713
9695e89
c1a7978
b4a3412
1f30a02
f064acd
e8ddb19
4afad9c
5e80e5b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,85 +6,70 @@ | |
@File : app.py | ||
""" | ||
import gradio as gr | ||
from metagpt.software_company import SoftwareCompany, SoftwareCompanyWithHuman | ||
from metagpt.roles import ProjectManager,\ | ||
ProductManager, Architect,\ | ||
Engineer, QaEngineer | ||
from metagpt.software_company import SoftwareCompany | ||
from metagpt.roles import ProjectManager,ProductManager, Architect,Engineer, QaEngineer | ||
from metagpt.roles.researcher import RESEARCH_PATH, Researcher | ||
from metagpt.const import PROJECT_ROOT | ||
import sys | ||
|
||
def clear_logs(): | ||
with open(PROJECT_ROOT / 'logs/log.txt', 'w') as f: | ||
f.write("") | ||
|
||
class Report: | ||
def __init__(self, role, action, sent_from, send_to, content): | ||
self.role = role | ||
self.action = action | ||
self.sent_from = sent_from | ||
self.send_to = send_to | ||
self.content = content | ||
|
||
async def startup(company_name : str, | ||
idea : str, | ||
staffs : list, | ||
investment : float = 6.0, | ||
n_round : int = 5, | ||
code_review : bool = True, | ||
staffs : list = ["ProjectManager", | ||
"ProductManager", | ||
"Architect"] | ||
)->SoftwareCompany: | ||
|
||
if company_name == "SoftwareCompany": | ||
company = SoftwareCompany() | ||
elif company_name == "SoftwareCompany_With_Human": | ||
company = SoftwareCompanyWithHuman() | ||
else: | ||
return "Company type not supported" | ||
if idea == "": | ||
return "Please input your idea" | ||
code_review : bool = False, | ||
auto_mode : bool = False, | ||
): | ||
global SoftwareCompany_Company | ||
|
||
if company_name == "SoftwareCompany": company = SoftwareCompany() | ||
else: return "Company type not supported" | ||
if idea == "": return "Please input your idea" | ||
staff_list = [] | ||
for staff in staffs: | ||
if staff == "ProjectManager": | ||
staff_list.append(ProjectManager()) | ||
elif staff == "ProductManager": | ||
staff_list.append(ProductManager()) | ||
elif staff == "Architect": | ||
staff_list.append(Architect()) | ||
elif staff == "Engineer": | ||
staff_list.append(Engineer(n_borg=5,use_code_review=code_review)) | ||
elif staff == "QaEngineer": | ||
staff_list.append(QaEngineer()) | ||
if staff == "ProjectManager": staff_list.append(ProjectManager()) | ||
elif staff == "ProductManager": staff_list.append(ProductManager()) | ||
elif staff == "Architect": staff_list.append(Architect()) | ||
elif staff == "Engineer": staff_list.append(Engineer(n_borg=5,use_code_review=code_review)) | ||
elif staff == "QaEngineer": staff_list.append(QaEngineer()) | ||
company.hire(staff_list) | ||
company.invest(investment) | ||
company.start_project(idea) | ||
# report all output to webui | ||
global SoftwareCompany_Company | ||
SoftwareCompany_Company = company | ||
if company_name == "SoftwareCompany": | ||
if auto_mode: | ||
company.environment.human_interaction = False | ||
await company.run(n_round) | ||
elif company_name == "SoftwareCompany_With_Human": | ||
await company.continue_run() | ||
return "Role: "+company.environment.short_term_history.role,\ | ||
"Action: "+str(company.environment.short_term_history.cause_by),\ | ||
company.environment.short_term_history.sent_from,\ | ||
company.environment.short_term_history.send_to,\ | ||
company.environment.short_term_history.content,\ | ||
company.environment.short_term_history.content | ||
else : | ||
company.environment.human_interaction = True | ||
report = Report(company.environment.short_term_history.role, | ||
str(company.environment.short_term_history.cause_by), | ||
company.environment.short_term_history.sent_from, | ||
company.environment.short_term_history.send_to, | ||
company.environment.short_term_history.content) | ||
return report.role, report.action, report.sent_from, report.send_to, report.content, report.content | ||
|
||
async def __continue(message_content : str): | ||
company = SoftwareCompany_Company | ||
company.environment.short_term_history.content = message_content | ||
company.environment.memory.add(company.environment.short_term_history) | ||
company.environment.history += f"\n{company.environment.short_term_history}" | ||
await company.continue_run() | ||
return "Role: "+company.environment.short_term_history.role,\ | ||
"Action: "+str(company.environment.short_term_history.cause_by),\ | ||
company.environment.short_term_history.sent_from,company.environment.short_term_history.send_to,\ | ||
company.environment.short_term_history.content,\ | ||
company.environment.short_term_history.content | ||
await company.run_one_round() | ||
report = Report(company.environment.short_term_history.role, | ||
str(company.environment.short_term_history.cause_by), | ||
company.environment.short_term_history.sent_from, | ||
company.environment.short_term_history.send_to, | ||
company.environment.short_term_history.content) | ||
return report.role, report.action, report.sent_from, report.send_to, report.content, report.content | ||
|
||
async def research_startup(language : str, | ||
topic : str): | ||
if language == "en-us": | ||
language = "en-us" | ||
elif language == "zh-ch": | ||
language = "zh-ch" | ||
else: | ||
raise Exception("Language not supported") | ||
async def research_startup(language : str, topic : str): | ||
role = Researcher(language="en-us") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 上面的判断逻辑与这里的实现无关。一般而言,我建议提交代码只提交在当时的最优解,尽可能不提交最优解之外的逻辑 |
||
await role.run(topic) | ||
return f"save report to {RESEARCH_PATH / f'{topic}.md'}." | ||
|
@@ -97,17 +82,17 @@ async def research_startup(language : str, | |
gr.Markdown(""" | ||
# MetaGPT | ||
""") | ||
|
||
with gr.Tabs(): | ||
with gr.TabItem("MetaGPT") as generate_tab: | ||
company_choise = gr.Dropdown(label = "Choose the company type",\ | ||
choices = ["SoftwareCompany", "SoftwareCompany_With_Human"],\ | ||
value = "SoftwareCompany_With_Human") | ||
company_choise = gr.Dropdown(label = "Choose the company type",choices = ["SoftwareCompany"],value = "SoftwareCompany") | ||
with gr.Row(): | ||
investment = gr.Slider(minimum=0.0, maximum=20.0, step=0.1, label="Investment",value = 6.0,\ | ||
info="The maxmium money you want to spend on the GPT generation") | ||
n_round = gr.Number( label="Round", value = 5, info="The maxmium round you want to run",visible = False) | ||
n_round = gr.Number( label="Round", value = 5, info="The maxmium round you want to run",visible = True) | ||
with gr.Row(): | ||
code_review = gr.Checkbox(label = "Whether to use code review", value = False) | ||
auto_mode = gr.Checkbox(label = "Whether to use auto mode", info = "run without human interaction", value = False) | ||
staffs = gr.CheckboxGroup(["ProjectManager", "ProductManager", "Architect", "Engineer", "QaEngineer"],\ | ||
label="Choose the staff you would like to hire",\ | ||
value = ["ProjectManager", "ProductManager", "Architect", "Engineer"]) | ||
|
@@ -129,9 +114,8 @@ async def research_startup(language : str, | |
output_content_metagpt = gr.Textbox(label="The phased output of MetaGPT, modify it as your will",\ | ||
max_lines=999,show_copy_button = True) | ||
output_content_markdown_metagpt = gr.Markdown(label="The markdown output of MetaGPT", visible = False) | ||
|
||
|
||
Start_MetaGPT.click(startup, [company_choise, idea, investment, n_round, code_review, staffs],\ | ||
|
||
Start_MetaGPT.click(startup, [company_choise, idea, staffs, investment, n_round, code_review, auto_mode],\ | ||
[output_role_metagpt,output_cause_metagpt,output_sent_from_metagpt,output_send_to_metagpt,\ | ||
output_content_metagpt,output_content_markdown_metagpt]) | ||
# clear_log.click(clear_logs, [],[]) | ||
|
@@ -144,6 +128,7 @@ async def research_startup(language : str, | |
if company_choise == "SoftwareCompany_With_Human" else True), [company_choise], [n_round]) | ||
show_markdown.change(lambda x: gr.update(visible = True if x == True else False),\ | ||
[show_markdown], [output_content_markdown_metagpt]) | ||
|
||
with gr.TabItem("Research") as research_tab: | ||
language = gr.Dropdown(label = "Choose the language", choices = ["en-us","zh-ch"], value = "en-us") | ||
topic = gr.Textbox(label="Your research topic, such as 'dataiku vs. datarobot'", value = "dataiku vs. datarobot") | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 删除中文版 |
This file was deleted.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
PEP8. 可以尝试使用PyCharm自带的format或者black / flake8