Create: mvp
This commit is contained in:
parent
51c27cabf2
commit
9fa87dbf16
17
poetry.lock
generated
17
poetry.lock
generated
@ -1978,6 +1978,21 @@ files = [
|
|||||||
[package.dependencies]
|
[package.dependencies]
|
||||||
six = ">=1.5"
|
six = ">=1.5"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "python-dotenv"
|
||||||
|
version = "1.0.0"
|
||||||
|
description = "Read key-value pairs from a .env file and set them as environment variables"
|
||||||
|
category = "main"
|
||||||
|
optional = false
|
||||||
|
python-versions = ">=3.8"
|
||||||
|
files = [
|
||||||
|
{file = "python-dotenv-1.0.0.tar.gz", hash = "sha256:a8df96034aae6d2d50a4ebe8216326c61c3eb64836776504fcca410e5937a3ba"},
|
||||||
|
{file = "python_dotenv-1.0.0-py3-none-any.whl", hash = "sha256:f5971a9226b701070a4bf2c38c89e5a3f0d64de8debda981d1db98583009122a"},
|
||||||
|
]
|
||||||
|
|
||||||
|
[package.extras]
|
||||||
|
cli = ["click (>=5.0)"]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "python-multipart"
|
name = "python-multipart"
|
||||||
version = "0.0.6"
|
version = "0.0.6"
|
||||||
@ -2636,4 +2651,4 @@ multidict = ">=4.0"
|
|||||||
[metadata]
|
[metadata]
|
||||||
lock-version = "2.0"
|
lock-version = "2.0"
|
||||||
python-versions = "^3.11"
|
python-versions = "^3.11"
|
||||||
content-hash = "190c777d4ffddd08f97be99418024b9eef296fe835bce89f16db821354f749c0"
|
content-hash = "45093343787af14605e9eaa3b71391b90bc039795a061b5d9e99e19f53620af7"
|
||||||
|
@ -13,11 +13,17 @@ gpt-index = "0.4.24"
|
|||||||
pypdf2 = "^3.0.1"
|
pypdf2 = "^3.0.1"
|
||||||
pycryptodome = "^3.17"
|
pycryptodome = "^3.17"
|
||||||
gradio = "^3.27.0"
|
gradio = "^3.27.0"
|
||||||
|
python-dotenv = "^1.0.0"
|
||||||
|
|
||||||
|
|
||||||
[tool.poetry.group.dev.dependencies]
|
[tool.poetry.group.dev.dependencies]
|
||||||
flake8 = "^6.0.0"
|
flake8 = "^6.0.0"
|
||||||
|
|
||||||
|
|
||||||
|
[tool.poetry.scripts]
|
||||||
|
chadgpt = "chadgpt.main:main"
|
||||||
|
|
||||||
|
|
||||||
[build-system]
|
[build-system]
|
||||||
requires = ["poetry-core"]
|
requires = ["poetry-core"]
|
||||||
build-backend = "poetry.core.masonry.api"
|
build-backend = "poetry.core.masonry.api"
|
||||||
|
@ -1,12 +1,10 @@
|
|||||||
#!/usr/bin/env python3
|
#!/usr/bin/env python3
|
||||||
import os
|
import os
|
||||||
import sys
|
import gradio as gr
|
||||||
import gradio
|
from dotenv import load_dotenv
|
||||||
from dotenv import load_dotenv, find_dotenv
|
|
||||||
from langchain.chat_models import ChatOpenAI
|
from langchain.chat_models import ChatOpenAI
|
||||||
from gpt_index import (
|
from gpt_index import (
|
||||||
SimpleDirectoryReader,
|
SimpleDirectoryReader,
|
||||||
GPTListIndex,
|
|
||||||
GPTSimpleVectorIndex,
|
GPTSimpleVectorIndex,
|
||||||
LLMPredictor,
|
LLMPredictor,
|
||||||
PromptHelper
|
PromptHelper
|
||||||
@ -15,7 +13,7 @@ from gpt_index import (
|
|||||||
|
|
||||||
def get_env():
|
def get_env():
|
||||||
if not os.environ.get("OPENAI_API_KEY"):
|
if not os.environ.get("OPENAI_API_KEY"):
|
||||||
load_dotenv(find_dotenv())
|
load_dotenv()
|
||||||
|
|
||||||
|
|
||||||
# parse hidden api key:
|
# parse hidden api key:
|
||||||
@ -50,28 +48,30 @@ def construct_index(directory_path):
|
|||||||
prompt_helper=prompt_helper
|
prompt_helper=prompt_helper
|
||||||
)
|
)
|
||||||
|
|
||||||
index.save_to_disk('index.json')
|
index_file = os.environ.get('DB_PATH') + "/index.json"
|
||||||
|
index.save_to_disk(index_file)
|
||||||
|
|
||||||
return index
|
return index
|
||||||
|
|
||||||
|
|
||||||
def chatbot(input_text):
|
def chatbot(input_text):
|
||||||
index = GPTSimpleVectorIndex.load_from_disk('index.json')
|
index_file = os.environ.get("DB_PATH") + "/index.json"
|
||||||
|
index = GPTSimpleVectorIndex.load_from_disk(index_file)
|
||||||
response = index.query(input_text, response_mode="compact")
|
response = index.query(input_text, response_mode="compact")
|
||||||
return response.response
|
return response.response
|
||||||
|
|
||||||
|
|
||||||
iface = gradio.Interface(
|
iface = gr.Interface(
|
||||||
fn=chatbot,
|
fn=chatbot,
|
||||||
inputs=gradio.components.Textbox(lines=7, label="Enter your text"),
|
inputs=gr.components.Textbox(lines=7, label="Enter your text"),
|
||||||
outputs="text",
|
outputs="text",
|
||||||
title="ISPsystem custom-trained AI Chatbot"
|
title="ISPsystem custom-trained AI Chatbot"
|
||||||
)
|
)
|
||||||
|
|
||||||
index = construct_index("../docs")
|
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
get_env()
|
get_env()
|
||||||
|
construct_index(os.environ.get("DB_PATH"))
|
||||||
iface.launch(share=False)
|
iface.launch(share=False)
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user