EagleLoveAI commited on
Commit
22d696c
·
1 Parent(s): 6a4a4e9

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -13
app.py CHANGED
@@ -30,20 +30,19 @@ from langchain.document_loaders import PDFMinerLoader
30
  from langchain.document_loaders import UnstructuredFileLoader
31
 
32
  disclaimer = ("""
33
- #### Disclaimer and Precautions
34
- ###### Use of this tool is at your own risk. The creator cannot be held responsible for any harm caused by this tool.
35
- ###### The creator is not responsible for any damages caused to users or third parties as a result of such content.
36
  """)
37
 
38
  # Configure Chroma
39
  persist_directory="/data/"
40
 
41
  #Convert local file to Embedding (txt file is better)
42
- loader = UnstructuredFileLoader('data/ChatGPT_S_ND.txt')
43
  paldoc = loader.load()
44
 
45
- openai.api_key = os.environ.get("OPENAI_API_KEY")
46
-
47
  #OPENAI_API_KEY = os.getenv('openai_api_key')
48
  #OPENAI_API_KEY = "openai_api_key"
49
 
@@ -58,9 +57,9 @@ vStore = Chroma.from_documents(paldocs, embeddings)
58
  from langchain.chains import RetrievalQA
59
  from langchain.chat_models import ChatOpenAI
60
 
61
- # RetrievalQA
62
  model = RetrievalQA.from_chain_type(
63
- llm=ChatOpenAI(temperature=0.5, model_name="gpt-3.5-turbo-16k", max_tokens = 256),
64
  chain_type="stuff",
65
  retriever=vStore.as_retriever()
66
  )
@@ -68,14 +67,14 @@ model = RetrievalQA.from_chain_type(
68
  #open as a demo Web app using Gradio
69
  import gradio as gr
70
  # 関数を定義
71
- def askandanswer(question, Language): return model.run("Please create a simple answer to the question from in " + Language + ". [Question] " + question)
72
  # Webアプリを作成
73
  app = gr.Interface(fn=askandanswer,
74
- inputs= [gr.Textbox(placeholder="Please input query "),
75
- gr.Dropdown(["中文 Chinese", "英語 English"], label="言語 Language")],
76
  outputs="text",
77
- title="Chat with Document(s) using OpenAI ChatGPT API and Text Embedding",
78
- description= "How to chat with any documents, PDFs, and books using OpenAI ChatGPT API and Text Embedding",
79
  article= (disclaimer),
80
  )
81
  # Webアプリを起動
 
30
  from langchain.document_loaders import UnstructuredFileLoader
31
 
32
  disclaimer = ("""
33
+ #### 注意事項及び免責事項 Disclaimer and Precautions
34
+ ###### ご利用はご自身の責任において行ってください。本ツールにより生じたいかなる損害についても、作成者は責任を負いかねます。 Use of this tool is at your own risk. The creator cannot be held responsible for any harm caused by this tool.
35
+ ###### 当該コンテンツに起因してご利用者様および第三者に損害が発生したとしても作成者は責任を負わないものとします。 The creator is not responsible for any damages caused to users or third parties as a result of such content.
36
  """)
37
 
38
  # Configure Chroma
39
  persist_directory="/data/"
40
 
41
  #Convert local file to Embedding (txt file is better)
42
+ loader = UnstructuredFileLoader('data/pal-end-of-life-trajectory0611 en.txt')
43
  paldoc = loader.load()
44
 
45
+ os.environ['OPENAI_API_KEY'] = os.getenv('openai_api_key')
 
46
  #OPENAI_API_KEY = os.getenv('openai_api_key')
47
  #OPENAI_API_KEY = "openai_api_key"
48
 
 
57
  from langchain.chains import RetrievalQA
58
  from langchain.chat_models import ChatOpenAI
59
 
60
+ # RetrievalQAチェーンの生成
61
  model = RetrievalQA.from_chain_type(
62
+ llm=ChatOpenAI(temperature=0.5, model_name="gpt-3.5-turbo", max_tokens = 256),
63
  chain_type="stuff",
64
  retriever=vStore.as_retriever()
65
  )
 
67
  #open as a demo Web app using Gradio
68
  import gradio as gr
69
  # 関数を定義
70
+ def askandanswer(question, Language): return model.run("Please create a simple answer to the question from family members of advanced cancer patients as an expert of palliative care and hospice care in " + Language + ". [Question] " + question)
71
  # Webアプリを作成
72
  app = gr.Interface(fn=askandanswer,
73
+ inputs= [gr.Textbox(placeholder="Please input query 質問を入力して下さい"),
74
+ gr.Dropdown(["日本語 Japanese", "英語 English"], label="言語 Language")],
75
  outputs="text",
76
+ title="終末期がん患者の家族サポートツール Empowering-Families-in-Cancer-Journey",
77
+ description= "これは「これからの過ごし方について(看取りのパンフレット)」についてのGPTを用いたQ&Aツールです. This is a Q&A tool for End-of-Life Care Brochure https://www.kanwacare.net/formedical/s_pamphlet/",
78
  article= (disclaimer),
79
  )
80
  # Webアプリを起動