Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,43 +1,19 @@
|
|
| 1 |
import json
|
| 2 |
-
from langchain.chains import llm
|
| 3 |
-
from ast import Index
|
| 4 |
-
from gpt_index import SimpleDirectoryReader, GPTListIndex, readers, GPTSimpleVectorIndex, LLMPredictor, PromptHelper
|
| 5 |
-
from langchain import OpenAI
|
| 6 |
-
import openai
|
| 7 |
-
import os
|
| 8 |
import streamlit as st
|
|
|
|
| 9 |
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
|
|
|
| 14 |
|
| 15 |
-
|
| 16 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 17 |
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
query = st.text_input("Tell me about Patrick Collison?")
|
| 21 |
-
|
| 22 |
-
# Use OpenAI to get a response to the query
|
| 23 |
-
response = openai.Completion.create(
|
| 24 |
-
engine="text-davinci-002",
|
| 25 |
-
prompt=f"Patrick Collison is a tech entrepreneur. {query}",
|
| 26 |
-
temperature=0.5,
|
| 27 |
-
max_tokens=1024,
|
| 28 |
-
top_p=1,
|
| 29 |
-
frequency_penalty=0,
|
| 30 |
-
presence_penalty=0
|
| 31 |
-
)
|
| 32 |
-
|
| 33 |
-
# Print the response
|
| 34 |
-
st.write(response.choices[0].text)
|
| 35 |
-
|
| 36 |
-
# Search the GPT index for the best response
|
| 37 |
-
result = gpt_index.query(response.choices[0].text)
|
| 38 |
-
|
| 39 |
-
# Print the result
|
| 40 |
-
st.write(result)
|
| 41 |
-
|
| 42 |
-
if __name__ == "__main__":
|
| 43 |
-
ask_patrick()
|
|
|
|
| 1 |
import json
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2 |
import streamlit as st
|
| 3 |
+
from gpt_index import GPTSimpleVectorIndex
|
| 4 |
|
| 5 |
+
def search_gpt_index():
|
| 6 |
+
# Load the GPT index from the file
|
| 7 |
+
with open('index.json', 'r') as f:
|
| 8 |
+
index_data = json.load(f)
|
| 9 |
+
gpt_index = GPTSimpleVectorIndex(index_data)
|
| 10 |
|
| 11 |
+
# Define the app layout
|
| 12 |
+
st.title('GPT Search')
|
| 13 |
+
query = st.text_input('Enter a query:')
|
| 14 |
+
if query:
|
| 15 |
+
result = gpt_index.query(query)
|
| 16 |
+
st.write(result)
|
| 17 |
|
| 18 |
+
if __name__ == '__main__':
|
| 19 |
+
search_gpt_index()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|