import langchain import os import openai from langchain.embeddings import OpenAIEmbeddings from langchain.vectorstores import Chroma from langchain import OpenAI, VectorDBQA import nltk from langchain.document_loaders import UnstructuredFileLoader from langchain.text_splitter import CharacterTextSplitter loader = UnstructuredFileLoader('RAJAGOPAL Thesis.txt') documents = loader.load() text_splitter = CharacterTextSplitter(chunk_size = 1000, chunk_overlap = 0) texts = text_splitter.split_documents(documents) openai.api_key = os.environ['OPENAI_API_KEY'] embeddings = OpenAIEmbeddings() doc_search = Chroma.from_documents(texts, embeddings) chain = VectorDBQA.from_chain_type(llm = OpenAI(), chain_type = "stuff", vectorstore = doc_search) def chat(input_text): return chain.run(input_text) import gradio as gr input_text = gr.inputs.Textbox(lines=7, label="Input") output_text = gr.outputs.Textbox(label="Output") gr.Interface( fn=chat, inputs=input_text, outputs=output_text, title="thesisGPT", flagging_enabled=False, description="A Conversational GPT based bot for exploring the thesis work done - AN AI-BASED FRAMEWORK AND DATA-DRIVEN METHODOLOGY FOR POST-PCR HIGH-RESOLUTION MELTING ANALYSIS.", theme="vertical", ).launch()