File size: 2,556 Bytes
9083c84
dd9022d
a5d600a
37d7b31
dd9022d
bd6aadd
a5d600a
bd6aadd
 
42c37e7
5106cd4
bd6aadd
5106cd4
bd6aadd
5106cd4
bd6aadd
5106cd4
bd6aadd
5106cd4
 
bd6aadd
 
3ee0620
cd8d62b
2e83dbc
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4cf0f40
8fe3e81
12ff56e
60525c8
cd8d62b
bdc87d1
12ff56e
8fe3e81
bdc87d1
cd8d62b
8fe3e81
95eb069
 
 
a5d600a
12ff56e
2e83dbc
5106cd4
24a063c
a5d600a
5106cd4
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
import gradio as gr
import json 
import os
from llama_index import SimpleDirectoryReader, GPTListIndex, readers, GPTSimpleVectorIndex, LLMPredictor, PromptHelper
from langchain import OpenAI
import sys

from IPython.display import Markdown, display

def construct_index(directory_path):

    max_input_size = 4096

    num_outputs = 2000

    max_chunk_overlap = 20

    chunk_size_limit = 600


    llm_predictor = LLMPredictor(llm=OpenAI(temperature=0.5, model_name="gpt-3.5-turbo", max_tokens=num_outputs))
    prompt_helper = PromptHelper(max_input_size, num_outputs, max_chunk_overlap, chunk_size_limit=chunk_size_limit)


'''

import tkinter as tk
from llama_index import GPTSimpleVectorIndex, LLMPredictor, PromptHelper
from langchain import OpenAI
from IPython.display import Markdown, display



# Define the GUI
class ChatBotGUI:
    def __init__(self, master):
        self.master = master
        master.title("Chat Bot")

        # Create a label and an entry for the question
        self.label = tk.Label(master, text="Ask me anything:")
        self.label.pack()

        self.entry = tk.Entry(master)
        self.entry.pack()

        # Create a button to submit the question
        self.button = tk.Button(master, text="Submit", command=self.submit_question)
        self.button.pack()

        # Create a text box to display the response
        self.textbox = tk.Text(master)
        self.textbox.pack()

    def submit_question(self):
        question = self.entry.get()
        response = ask_ai(question)
        self.textbox.insert(tk.END, "You: " + question + "\n")
        self.textbox.insert(tk.END, "Bot: " + response + "\n\n")
        self.entry.delete(0, tk.END)

# Create an instance of the GUI and start the main loop
root = tk.Tk()
chatbot_gui = ChatBotGUI(root)
root.mainloop()
'''


os.environ["OPENAI_API_KEY"] = "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"
construct_index("data")
def ask_ai(question,openai_api_key):
    
    if openai_api_key == "":
        os.environ["OPENAI_API_KEY"] = "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"
    else:
        os.environ["OPENAI_API_KEY"] = openai_api_key
        construct_index("data")
        
    index = GPTSimpleVectorIndex.load_from_disk('index.json')
    response = index.query(question, response_mode="compact")
    return response.response


api_key = gr.inputs.Textbox(label="Paste OPENAI API Key (Or left it blank to use default api)")
iface = gr.Interface(fn=ask_ai, inputs=["text", api_key], outputs="text", title="Chatbot")


iface.launch()