見出し画像

GPT-4とBardを活用した会社分析のWebアプリの作成方法2

前回、GPT-4を利用したフレームワークのウェブアプリの作成方法を紹介いたしました。


今回は、GPT-4だけじゃなくてBardも利用できるようにしました。


言語モデルの選択

また、会社分析のためのフレームワークも少し追加しました。


分析用のフレームワーク

また、会社分析だけじゃなくて、会社自体の情報も取得できるように、Company Informationという項目を作成してみました。


Company Informationの結果


今回のコードは、app.pyとして以下保存してください。Your-OpenAIAPIKeyは、OpenAIで取得したAPIキーを記載ください。また、Your-BARDAPIKEYの取得方法は、下記を参考にしてください。


import os
import openai
from bardapi import Bard
import streamlit as st

#Set the API Key
openai.api_key="Your-OpenAIAPIKey"
os.environ['_BARD_API_KEY']="Your-BARDAPIKEY"

#Set the model
openaimodel="gpt-4"

#Title
st.title('🤗 MBA Framework Powered by GPT-4 and Bard')
prompt = st.text_input('Input the company name here')

#Select the language
sel_language=st.sidebar.radio("Language", ["English","Japanese","Chinese","Spanish"])

#select the LLM
sel_llm=st.sidebar.radio("Language Model",["GPT-4","Bard"])

#Select the framework
sel_framework = st.sidebar.radio(
    "MBA Framework",
    ("PESTEL Analysis","Porter's Five Forces Analysis","SWOT Analysis","Scenario analysis","Ansoff's Growth Matrix",
     "BCG Matrix","GE McKinsey Matrix","Resource-Based View analysis","Balanced Scorecard","Core conpetency analysis",
     "VRIO Analysis","Blue Ocean Strategy","7S Framework","Balanced Scorecard","Lean Startup","Business Model Canvas",
     "Customer Journey Map","5C Analysis","4P's (Product, Price, Place, Promotion)","STP (Segmentation, Targeting, Positioning)",
     "RACI Matrix (Responsible, Accountable, Consulted, Informed)","OKR (Objectives and Key Results)",
     "PDCA Cycle (Plan, Do, Check, Act)"
     )
)

#Push the button to run the model to analyze the company
if st.button('Analyze'):
    st.write('Analyzing the company...')
    if sel_llm=="GPT-4":
    # OpenAI
        response1=openai.ChatCompletion.create(
                    model=openaimodel,
                    messages=[
                        {"role":"user", "content": f"Analyze {prompt} using {sel_framework} in {sel_language}. "}
                    ]   
                    )
        responseOpenAI=response1['choices'][0]['message']['content']
        st.write( f"Company name is {prompt}: {responseOpenAI}")
    if sel_llm=="Bard":
    #Google Bard
        responseBard= Bard().get_answer(f"Analyze {prompt} using {sel_framework} in {sel_language}.")['content']
        st.write( f"Company name is {prompt}: {responseBard}")

#Push the button to run the model to show company information
if st.button("Company Information"):
    st.write("Creating company information")
    if sel_llm=="GPT-4":
         #OpenAI         response2=openai.ChatCompletion.create(
               model=openaimodel,
                messages=[
                  {"role":"user", "content": f"Show company information about {prompt} in {sel_language}."}
                ]
                )
        responseOpenAI=response2['choices'][0]['message']['content']
        st.write(f"{prompt} information is below :{responseOpenAI}")
    if sel_llm=="Bard":
        #Google Bard
        responseBard= Bard().get_answer(f"Show company information about {prompt} in {sel_language}.")['content']
        st.write( f"{prompt} information is below : {responseBard}")


次に、下記をrequirements.txtとして保存してください。

streamlit
openai
bardapi


次に、自分のPC環境で下記を実行します。

python -m venv venv
venv\Scripts\Activate
pip install -r requirements.txt
streamlit run app.py

上記を実行すると、下記の画面が出てきます。


初期画面

表示言語や、言語モデルをGPT-4かBardか選んで、色々と会社を分析することができます。


次回以降の改良点は、Company Informationの情報を充実させたり、分析結果をテーブル表記とかで見やすくしたり、フレームワークをもう少しカテゴリ化して整理して表示できるように考えています。


この記事が気に入ったらサポートをしてみませんか?