Spaces:
Runtime error
Runtime error
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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 |
+
# Load the GPT index from the file
|
| 11 |
+
with open('index.json', 'r') as f:
|
| 12 |
+
index_data = json.load(f)
|
| 13 |
+
gpt_index = GPTSimpleVectorIndex(index_data)
|
| 14 |
+
|
| 15 |
+
OPENAI_API_KEY = st.secrets["OPENAI_API_KEY"]
|
| 16 |
+
os.environ["OPENAI_API_KEY"] = OPENAI_API_KEY
|
| 17 |
+
|
| 18 |
+
def ask_patrick():
|
| 19 |
+
# Get the user's query
|
| 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()
|