Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -24,18 +24,31 @@ def write_string_to_file(text, filename):
|
|
| 24 |
with open(filename, 'w') as file:
|
| 25 |
file.write(text)
|
| 26 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 27 |
|
| 28 |
def ui():
|
| 29 |
|
| 30 |
api_key = st.text_input('Enter your OpenAI key here: ')
|
| 31 |
-
if api_key is not None:
|
| 32 |
os.environ["OPENAI_API_KEY"] = api_key
|
| 33 |
openai.api_key = os.environ["OPENAI_API_KEY"]
|
| 34 |
logging.basicConfig(stream=sys.stdout, level=logging.INFO)
|
| 35 |
logging.getLogger().addHandler(logging.StreamHandler(stream=sys.stdout))
|
| 36 |
|
| 37 |
topic_name= st.text_input('Enter your topic for Wikipedia: ')
|
| 38 |
-
if topic_name is not None:
|
| 39 |
page_object = wikipedia.page(topic_name)
|
| 40 |
content = page_object.content
|
| 41 |
filename = f"./Data/{topic_name}.txt"
|
|
@@ -46,7 +59,7 @@ def ui():
|
|
| 46 |
|
| 47 |
|
| 48 |
query_str= st.text_input('Enter your query for the document: ')
|
| 49 |
-
if query_str is not None:
|
| 50 |
query_engine = index.as_query_engine()
|
| 51 |
response = query_engine.query(query_str)
|
| 52 |
hyde = HyDEQueryTransform(include_original=True)
|
|
@@ -54,7 +67,8 @@ def ui():
|
|
| 54 |
|
| 55 |
response = hyde_query_engine.query(query_str)
|
| 56 |
query_bundle = hyde(query_str)
|
| 57 |
-
hyde_doc = query_bundle.embedding_strs[0]
|
|
|
|
| 58 |
st.text(hyde_doc)
|
| 59 |
|
| 60 |
|
|
@@ -63,10 +77,3 @@ if __name__=="__main__":
|
|
| 63 |
ui()
|
| 64 |
|
| 65 |
|
| 66 |
-
|
| 67 |
-
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
|
| 71 |
-
|
| 72 |
-
|
|
|
|
| 24 |
with open(filename, 'w') as file:
|
| 25 |
file.write(text)
|
| 26 |
|
| 27 |
+
def remove_scrollbar():
|
| 28 |
+
# Apply custom CSS to remove the scrollbar
|
| 29 |
+
st.markdown(
|
| 30 |
+
"""
|
| 31 |
+
<style>
|
| 32 |
+
.css-1l02zno {
|
| 33 |
+
overflow: hidden !important;
|
| 34 |
+
}
|
| 35 |
+
</style>
|
| 36 |
+
""",
|
| 37 |
+
unsafe_allow_html=True
|
| 38 |
+
)
|
| 39 |
+
|
| 40 |
|
| 41 |
def ui():
|
| 42 |
|
| 43 |
api_key = st.text_input('Enter your OpenAI key here: ')
|
| 44 |
+
if api_key is not None and api_key != '':
|
| 45 |
os.environ["OPENAI_API_KEY"] = api_key
|
| 46 |
openai.api_key = os.environ["OPENAI_API_KEY"]
|
| 47 |
logging.basicConfig(stream=sys.stdout, level=logging.INFO)
|
| 48 |
logging.getLogger().addHandler(logging.StreamHandler(stream=sys.stdout))
|
| 49 |
|
| 50 |
topic_name= st.text_input('Enter your topic for Wikipedia: ')
|
| 51 |
+
if topic_name is not None and topic_name!='name':
|
| 52 |
page_object = wikipedia.page(topic_name)
|
| 53 |
content = page_object.content
|
| 54 |
filename = f"./Data/{topic_name}.txt"
|
|
|
|
| 59 |
|
| 60 |
|
| 61 |
query_str= st.text_input('Enter your query for the document: ')
|
| 62 |
+
if query_str is not None and query_str!='':
|
| 63 |
query_engine = index.as_query_engine()
|
| 64 |
response = query_engine.query(query_str)
|
| 65 |
hyde = HyDEQueryTransform(include_original=True)
|
|
|
|
| 67 |
|
| 68 |
response = hyde_query_engine.query(query_str)
|
| 69 |
query_bundle = hyde(query_str)
|
| 70 |
+
hyde_doc = query_bundle.embedding_strs[0]
|
| 71 |
+
remove_scrollbar()
|
| 72 |
st.text(hyde_doc)
|
| 73 |
|
| 74 |
|
|
|
|
| 77 |
ui()
|
| 78 |
|
| 79 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|