Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -1,51 +1,51 @@
|
|
1 |
-
from flask import Flask, render_template, request
|
2 |
-
from knowledgeassistant.components.summarization import DataSummarization
|
3 |
-
from knowledgeassistant.components.keywordextraction import KeywordExtraction
|
4 |
-
from knowledgeassistant.components.RAG import RAG
|
5 |
-
from knowledgeassistant.entity.config_entity import DataSummarizationConfig, PipelineConfig, DataInputConfig, KeywordExtractionConfig, RAGConfig
|
6 |
-
from knowledgeassistant.utils.main_utils.utils import write_txt_file, read_txt_file
|
7 |
-
|
8 |
-
app = Flask(__name__)
|
9 |
-
|
10 |
-
@app.route('/', methods=['GET', 'POST'])
|
11 |
-
def home():
|
12 |
-
if request.method == 'POST':
|
13 |
-
pipeline_config = PipelineConfig()
|
14 |
-
data_input_config = DataInputConfig(pipeline_config)
|
15 |
-
|
16 |
-
user_text = request.form['user_text']
|
17 |
-
user_option = request.form['tasks']
|
18 |
-
result_text = ""
|
19 |
-
|
20 |
-
if user_option == "Q&A":
|
21 |
-
user_question = request.form['user_question']
|
22 |
-
else:
|
23 |
-
user_number = int(request.form['user_number'])
|
24 |
-
|
25 |
-
input_text_path = data_input_config.input_text_file_path
|
26 |
-
write_txt_file(input_text_path, user_text, replace=True)
|
27 |
-
|
28 |
-
if user_option == "summarization":
|
29 |
-
data_summarization_config = DataSummarizationConfig(pipeline_config)
|
30 |
-
summarizer = DataSummarization(data_summarization_config)
|
31 |
-
file_path = data_summarization_config.summarized_text_file_path
|
32 |
-
summarizer.initiate_data_summarization(input_text_path=input_text_path, min_length=int(user_number))
|
33 |
-
elif user_option == "keywords":
|
34 |
-
keyword_extraction_config = KeywordExtractionConfig(pipeline_config)
|
35 |
-
extractor = KeywordExtraction(keyword_extraction_config)
|
36 |
-
file_path = keyword_extraction_config.extracted_keywords_file_path
|
37 |
-
extractor.initiate_keyword_extraction(input_text_path=input_text_path, keywords_count=int(user_number))
|
38 |
-
elif user_option == "Q&A":
|
39 |
-
rag_config = RAGConfig(pipeline_config)
|
40 |
-
rag = RAG(rag_config)
|
41 |
-
file_path = rag_config.rag_generated_text_path
|
42 |
-
rag.initiate_rag(input_text_path=input_text_path, query=user_question)
|
43 |
-
|
44 |
-
result_text = read_txt_file(file_path=file_path)
|
45 |
-
|
46 |
-
return render_template("index.html", task=user_option, text=result_text, user_text=user_text)
|
47 |
-
|
48 |
-
return render_template("index.html", task=None, text=None, user_text=None)
|
49 |
-
|
50 |
-
if __name__ == '__main__':
|
51 |
-
app.run(host='0.0.0.0', port=
|
|
|
1 |
+
from flask import Flask, render_template, request
|
2 |
+
from knowledgeassistant.components.summarization import DataSummarization
|
3 |
+
from knowledgeassistant.components.keywordextraction import KeywordExtraction
|
4 |
+
from knowledgeassistant.components.RAG import RAG
|
5 |
+
from knowledgeassistant.entity.config_entity import DataSummarizationConfig, PipelineConfig, DataInputConfig, KeywordExtractionConfig, RAGConfig
|
6 |
+
from knowledgeassistant.utils.main_utils.utils import write_txt_file, read_txt_file
|
7 |
+
|
8 |
+
app = Flask(__name__)
|
9 |
+
|
10 |
+
@app.route('/', methods=['GET', 'POST'])
|
11 |
+
def home():
|
12 |
+
if request.method == 'POST':
|
13 |
+
pipeline_config = PipelineConfig()
|
14 |
+
data_input_config = DataInputConfig(pipeline_config)
|
15 |
+
|
16 |
+
user_text = request.form['user_text']
|
17 |
+
user_option = request.form['tasks']
|
18 |
+
result_text = ""
|
19 |
+
|
20 |
+
if user_option == "Q&A":
|
21 |
+
user_question = request.form['user_question']
|
22 |
+
else:
|
23 |
+
user_number = int(request.form['user_number'])
|
24 |
+
|
25 |
+
input_text_path = data_input_config.input_text_file_path
|
26 |
+
write_txt_file(input_text_path, user_text, replace=True)
|
27 |
+
|
28 |
+
if user_option == "summarization":
|
29 |
+
data_summarization_config = DataSummarizationConfig(pipeline_config)
|
30 |
+
summarizer = DataSummarization(data_summarization_config)
|
31 |
+
file_path = data_summarization_config.summarized_text_file_path
|
32 |
+
summarizer.initiate_data_summarization(input_text_path=input_text_path, min_length=int(user_number))
|
33 |
+
elif user_option == "keywords":
|
34 |
+
keyword_extraction_config = KeywordExtractionConfig(pipeline_config)
|
35 |
+
extractor = KeywordExtraction(keyword_extraction_config)
|
36 |
+
file_path = keyword_extraction_config.extracted_keywords_file_path
|
37 |
+
extractor.initiate_keyword_extraction(input_text_path=input_text_path, keywords_count=int(user_number))
|
38 |
+
elif user_option == "Q&A":
|
39 |
+
rag_config = RAGConfig(pipeline_config)
|
40 |
+
rag = RAG(rag_config)
|
41 |
+
file_path = rag_config.rag_generated_text_path
|
42 |
+
rag.initiate_rag(input_text_path=input_text_path, query=user_question)
|
43 |
+
|
44 |
+
result_text = read_txt_file(file_path=file_path)
|
45 |
+
|
46 |
+
return render_template("index.html", task=user_option, text=result_text, user_text=user_text)
|
47 |
+
|
48 |
+
return render_template("index.html", task=None, text=None, user_text=None)
|
49 |
+
|
50 |
+
if __name__ == '__main__':
|
51 |
+
app.run(debug=True, host='0.0.0.0', port=7860)
|