-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from Scylidose/streamlit
Streamlit and GPT models integration
- Loading branch information
Showing
6 changed files
with
147 additions
and
83 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
[logger] | ||
|
||
# Level of logging: 'error', 'warning', 'info', or 'debug'. | ||
# Default: 'info' | ||
level = "info" | ||
|
||
[server] | ||
|
||
# If false, will attempt to open a browser window on start. | ||
# Default: false unless (1) we are on a Linux box where DISPLAY is unset, or (2) we are running in the Streamlit Atom plugin. | ||
headless = true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,33 +1,57 @@ | ||
import os | ||
import streamlit as st | ||
import openai | ||
|
||
from src import extract, preprocess, scraping, answer, model, export_doc | ||
|
||
def main(): | ||
website = "https://nomanssky.fandom.com/" | ||
openai.api_key = os.environ['OPENAI_API_KEY'] | ||
|
||
st.title("NMS Data Extraction and Question Answering") | ||
|
||
website = st.text_input("Enter the website URL:", "https://nomanssky.fandom.com/") | ||
websites_file = "data/websites.json" | ||
documents_dir = "data/documents" | ||
output_file = "data/links.csv" | ||
db_dir = "data/whoosh" | ||
child_depth = 1 | ||
child_depth = st.slider("Select child depth:", 1, 10, 1) | ||
|
||
if st.button("Start Data Extraction"): | ||
st.text("Starting data extraction...") | ||
scraping.check_websites(website, websites_file, child_depth) | ||
st.text("Data extraction completed.") | ||
|
||
if st.button("Export to CSV"): | ||
st.text("Exporting data to CSV...") | ||
extract.json_to_csv(websites_file, output_file) | ||
st.text("Data exported to CSV.") | ||
|
||
print("\n-----------------------\n") | ||
scraping.check_websites(website, websites_file, child_depth) | ||
print("\n-----------------------\n") | ||
extract.json_to_csv(websites_file, output_file) | ||
print("\n-----------------------\n") | ||
extract.extract_html_text(output_file) | ||
print("\n-----------------------\n") | ||
preprocess.add_preprocessed_text_website(output_file) | ||
if st.button("Extract HTML Text"): | ||
st.text("Extracting HTML text...") | ||
extract.extract_html_text(output_file) | ||
st.text("HTML text extraction completed.") | ||
|
||
query_text = "What is the release date of No Man\'s sky?" | ||
model_choice = "DeepPavlov" | ||
if st.button("Preprocess Text"): | ||
st.text("Preprocessing text...") | ||
preprocess.add_preprocessed_text_website(output_file) | ||
st.text("Text preprocessing completed.") | ||
|
||
if model_choice == "DeepPavlov": | ||
model_object = model.configure_deeppavlov() | ||
elif model_choice == "Haystack": | ||
export_doc.export_documents(output_file, documents_dir) | ||
model_object = model.configure_haystack(documents_dir) | ||
query_text = st.text_input("Enter your question:", "What is the release date of No Man's Sky?") | ||
model_choice = st.selectbox("Select a model:", ["DeepPavlov", "GPT 3.5 - 4k token", "GPT 3.5 - 16k token"]) | ||
|
||
answer.answer_question(model_choice, model_object, query_text, output_file, db_dir) | ||
if st.button("Answer Question"): | ||
st.text("Answering the question...") | ||
if model_choice == "DeepPavlov": | ||
model_object = model.configure_deeppavlov() | ||
elif model_choice == "GPT 3.5 - 4k token": | ||
model_object = "gpt-3.5-4k-tokens" | ||
model_choice = "gpt-3.5-4k-tokens" | ||
elif model_choice == "GPT 3.5 - 16k token": | ||
model_object = "gpt-3.5-4k-tokens" | ||
model_choice = "gpt-3.5-16k-tokens" | ||
|
||
answered_question=answer.answer_question(model_choice, model_object, query_text, output_file, db_dir) | ||
st.text_area("Answer:", answered_question) | ||
|
||
if __name__ == '__main__': | ||
main() | ||
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters