Spaces:
Sleeping
Sleeping
Download test.py from tsarprince/moobidesk: direct link, hf CLI and curl.
- Browser
- Download file 1.48 kB
-
https://huggingface.co/spaces/tsarprince/moobidesk/resolve/main/test.py
- Command line
-
hf download hf://spaces/tsarprince/moobidesk/test.py
-
curl -L -o test.py https://huggingface.co/spaces/tsarprince/moobidesk/resolve/main/test.py
1.48 kB
| from gpt_index import SimpleDirectoryReader, GPTListIndex, GPTSimpleVectorIndex, LLMPredictor, PromptHelper | |
| from langchain.chat_models import ChatOpenAI | |
| import gradio as gr | |
| from dotenv import load_dotenv | |
| load_dotenv() | |
| DOCS_PATH = 'docs' | |
| INDEX_PATH = 'index.json' | |
| def construct_index(directory_path): | |
| max_input_size = 4096 | |
| num_outputs = 512 | |
| max_chunk_overlap = 20 | |
| chunk_size_limit = 600 | |
| prompt_helper = PromptHelper( | |
| max_input_size, num_outputs, max_chunk_overlap, chunk_size_limit=chunk_size_limit) | |
| llm_predictor = LLMPredictor(llm=ChatOpenAI( | |
| temperature=0.2, model_name="gpt-3.5-turbo", max_tokens=num_outputs)) | |
| documents = SimpleDirectoryReader(directory_path).load_data() | |
| index = GPTSimpleVectorIndex( | |
| documents, llm_predictor=llm_predictor, prompt_helper=prompt_helper) | |
| index.save_to_disk(INDEX_PATH) | |
| return index | |
| def chatbot(input_text): | |
| index = GPTSimpleVectorIndex.load_from_disk(INDEX_PATH) | |
| # response = index.query(input_text, response_mode="compact") | |
| response = index.query(input_text) | |
| return response.response | |
| iface = gr.Interface(fn=chatbot, | |
| inputs=gr.components.Textbox( | |
| lines=7, label="Enter your text"), | |
| outputs="text", | |
| title="Moobidesk's AI Chatbot - POC") | |
| # index = construct_index(DOCS_PATH) | |
| # iface.launch(share=True) # dev | |
| iface.launch() # prod | |