Spaces:
Running
Running
Commit ·
05227ef
1
Parent(s): a404ec2
removed Azure
Browse files- app.py +4 -17
- create_index.py +3 -42
- docs/{PSPOT-QA.txt → PSPOT.txt} +0 -0
app.py
CHANGED
|
@@ -1,33 +1,20 @@
|
|
| 1 |
-
from dotenv import load_dotenv
|
| 2 |
-
from llama_index import (
|
| 3 |
-
GPTVectorStoreIndex, SimpleDirectoryReader,
|
| 4 |
-
ServiceContext, LLMPredictor, PromptHelper,
|
| 5 |
-
StorageContext, load_index_from_storage
|
| 6 |
-
)
|
| 7 |
from langchain.chat_models import ChatOpenAI
|
|
|
|
|
|
|
|
|
|
| 8 |
import gradio as gr
|
| 9 |
import os
|
| 10 |
|
| 11 |
-
load_dotenv()
|
| 12 |
-
OPENAI_API_KEY=os.getenv("OPENAI_API_KEY")
|
| 13 |
-
AZURE_BASE_URL=os.getenv("AZURE_BASE_URL")
|
| 14 |
-
AZURE_DEPLOYMENT_NAME=os.getenv("AZURE_DEPLOYMENT_NAME")
|
| 15 |
-
AZURE_OPENAI_API_KEY=os.getenv("AZURE_OPENAI_API_KEY")
|
| 16 |
-
AZURE_OPENAI_API_VERSION=os.getenv("AZURE_OPENAI_API_VERSION")
|
| 17 |
-
|
| 18 |
def chatbot(input_text):
|
| 19 |
storage_context = StorageContext.from_defaults(persist_dir="./storage")
|
| 20 |
index = load_index_from_storage(storage_context)
|
| 21 |
-
|
| 22 |
qe = index.as_query_engine()
|
| 23 |
response = qe.query(input_text)
|
| 24 |
-
|
| 25 |
return response.response
|
| 26 |
|
| 27 |
-
|
| 28 |
iface = gr.Interface(fn=chatbot,
|
| 29 |
inputs=gr.components.Textbox(lines=7, label="Enter your text"),
|
| 30 |
outputs="text",
|
| 31 |
title="Custom-trained AI Chatbot")
|
| 32 |
-
|
| 33 |
iface.launch()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
from langchain.chat_models import ChatOpenAI
|
| 2 |
+
from llama_index import StorageContext, load_index_from_storage
|
| 3 |
+
from dotenv import load_dotenv
|
| 4 |
+
import openai
|
| 5 |
import gradio as gr
|
| 6 |
import os
|
| 7 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 8 |
def chatbot(input_text):
|
| 9 |
storage_context = StorageContext.from_defaults(persist_dir="./storage")
|
| 10 |
index = load_index_from_storage(storage_context)
|
|
|
|
| 11 |
qe = index.as_query_engine()
|
| 12 |
response = qe.query(input_text)
|
|
|
|
| 13 |
return response.response
|
| 14 |
|
| 15 |
+
load_dotenv()
|
| 16 |
iface = gr.Interface(fn=chatbot,
|
| 17 |
inputs=gr.components.Textbox(lines=7, label="Enter your text"),
|
| 18 |
outputs="text",
|
| 19 |
title="Custom-trained AI Chatbot")
|
|
|
|
| 20 |
iface.launch()
|
create_index.py
CHANGED
|
@@ -1,51 +1,12 @@
|
|
| 1 |
from dotenv import load_dotenv
|
| 2 |
-
from llama_index import
|
| 3 |
-
GPTVectorStoreIndex, SimpleDirectoryReader,
|
| 4 |
-
ServiceContext, LLMPredictor, PromptHelper,
|
| 5 |
-
)
|
| 6 |
-
from langchain.chat_models import ChatOpenAI
|
| 7 |
import os
|
| 8 |
|
| 9 |
-
load_dotenv()
|
| 10 |
-
OPENAI_API_KEY=os.getenv("OPENAI_API_KEY")
|
| 11 |
-
AZURE_BASE_URL=os.getenv("AZURE_BASE_URL")
|
| 12 |
-
AZURE_DEPLOYMENT_NAME=os.getenv("AZURE_DEPLOYMENT_NAME")
|
| 13 |
-
AZURE_OPENAI_API_KEY=os.getenv("AZURE_OPENAI_API_KEY")
|
| 14 |
-
AZURE_OPENAI_API_VERSION=os.getenv("AZURE_OPENAI_API_VERSION")
|
| 15 |
-
|
| 16 |
def construct_index(directory_path):
|
| 17 |
-
max_input_size = 4096
|
| 18 |
-
num_outputs = 512
|
| 19 |
-
max_chunk_overlap = 20
|
| 20 |
-
chunk_size_limit = 600
|
| 21 |
-
|
| 22 |
-
prompt_helper = PromptHelper(
|
| 23 |
-
max_input_size, num_outputs, max_chunk_overlap, chunk_size_limit=chunk_size_limit
|
| 24 |
-
)
|
| 25 |
-
|
| 26 |
-
llm_predictor = LLMPredictor(
|
| 27 |
-
#llm=ChatOpenAI(temperature=0.7, model_name="gpt-3.5-turbo", max_tokens=num_outputs)
|
| 28 |
-
|
| 29 |
-
llm = AzureChatOpenAI(
|
| 30 |
-
openai_api_base=AZURE_BASE_URL,
|
| 31 |
-
openai_api_version=AZURE_OPENAI_API_VERSION,
|
| 32 |
-
deployment_name=AZURE_OPENAI_DEPLOYMENT_NAME,
|
| 33 |
-
openai_api_key=AZURE_OPENAI_API_KEY,
|
| 34 |
-
openai_api_type = "azure",
|
| 35 |
-
)
|
| 36 |
-
)
|
| 37 |
-
|
| 38 |
-
service_context = ServiceContext.from_defaults(
|
| 39 |
-
llm_predictor=llm_predictor, prompt_helper=prompt_helper
|
| 40 |
-
)
|
| 41 |
-
|
| 42 |
documents = SimpleDirectoryReader(directory_path).load_data()
|
| 43 |
-
|
| 44 |
-
index = GPTVectorStoreIndex.from_documents(
|
| 45 |
-
documents, service_context=service_context
|
| 46 |
-
)
|
| 47 |
index.storage_context.persist()
|
| 48 |
-
|
| 49 |
return index
|
| 50 |
|
|
|
|
| 51 |
index = construct_index("docs")
|
|
|
|
| 1 |
from dotenv import load_dotenv
|
| 2 |
+
from llama_index import GPTVectorStoreIndex, SimpleDirectoryReader
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3 |
import os
|
| 4 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 5 |
def construct_index(directory_path):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 6 |
documents = SimpleDirectoryReader(directory_path).load_data()
|
| 7 |
+
index = GPTVectorStoreIndex.from_documents(documents)
|
|
|
|
|
|
|
|
|
|
| 8 |
index.storage_context.persist()
|
|
|
|
| 9 |
return index
|
| 10 |
|
| 11 |
+
load_dotenv()
|
| 12 |
index = construct_index("docs")
|
docs/{PSPOT-QA.txt → PSPOT.txt}
RENAMED
|
File without changes
|