Spaces:
Sleeping
Sleeping
Link Caching and Moving Download to Sidebar
Browse files
app.py
CHANGED
@@ -20,7 +20,6 @@ nlp = spacy.load("en_core_web_sm")
|
|
20 |
user_agent = 'QGen/1.0 ([email protected])'
|
21 |
wiki_wiki = wikipediaapi.Wikipedia(user_agent= user_agent,language='en')
|
22 |
|
23 |
-
|
24 |
model = None
|
25 |
tokenizer = None
|
26 |
def load_model():
|
@@ -71,6 +70,7 @@ def map_keywords_to_sentences(text, keywords, context_window_size):
|
|
71 |
return keyword_sentence_mapping
|
72 |
|
73 |
# Function to perform entity linking using Wikipedia API
|
|
|
74 |
def entity_linking(keyword):
|
75 |
page = wiki_wiki.page(keyword)
|
76 |
if page.exists():
|
@@ -78,7 +78,7 @@ def entity_linking(keyword):
|
|
78 |
return None
|
79 |
|
80 |
# Function to generate questions using beam search
|
81 |
-
def generate_question(context, answer, num_beams
|
82 |
input_text = f"<context> {context} <answer> {answer}"
|
83 |
input_ids = tokenizer.encode(input_text, return_tensors='pt')
|
84 |
outputs = model.generate(input_ids, num_beams=num_beams, early_stopping=True)
|
@@ -140,21 +140,13 @@ if st.button("Generate Questions"):
|
|
140 |
|
141 |
# Export buttons
|
142 |
if data is not None:
|
143 |
-
|
144 |
-
|
145 |
-
|
146 |
-
|
147 |
-
# st.download_button(label="Download CSV", data=csv_data, file_name='questions.csv', mime='text/csv')
|
148 |
-
csv_data = export_to_csv(data)
|
149 |
-
st.download_button(label="Download CSV", data=csv_data, file_name='questions.csv', mime='text/csv')
|
150 |
|
151 |
-
|
152 |
-
|
153 |
-
# pdf_data = export_to_pdf(data)
|
154 |
-
# st.success("Questions exported to questions.pdf")
|
155 |
-
# st.download_button(label="Download PDF", data=pdf_data, file_name='questions.pdf', mime='application/pdf')
|
156 |
-
pdf_data = export_to_pdf(data)
|
157 |
-
st.download_button(label="Download PDF", data=pdf_data, file_name='questions.pdf', mime='application/pdf')
|
158 |
|
159 |
else:
|
160 |
st.write("Please enter some text to generate questions.")
|
|
|
20 |
user_agent = 'QGen/1.0 ([email protected])'
|
21 |
wiki_wiki = wikipediaapi.Wikipedia(user_agent= user_agent,language='en')
|
22 |
|
|
|
23 |
model = None
|
24 |
tokenizer = None
|
25 |
def load_model():
|
|
|
70 |
return keyword_sentence_mapping
|
71 |
|
72 |
# Function to perform entity linking using Wikipedia API
|
73 |
+
@lru_cache(maxsize=128)
|
74 |
def entity_linking(keyword):
|
75 |
page = wiki_wiki.page(keyword)
|
76 |
if page.exists():
|
|
|
78 |
return None
|
79 |
|
80 |
# Function to generate questions using beam search
|
81 |
+
def generate_question(context, answer, num_beams):
|
82 |
input_text = f"<context> {context} <answer> {answer}"
|
83 |
input_ids = tokenizer.encode(input_text, return_tensors='pt')
|
84 |
outputs = model.generate(input_ids, num_beams=num_beams, early_stopping=True)
|
|
|
140 |
|
141 |
# Export buttons
|
142 |
if data is not None:
|
143 |
+
with st.sidebar:
|
144 |
+
st.subheader('Download Content')
|
145 |
+
csv_data = export_to_csv(data)
|
146 |
+
st.download_button(label="CSV Format", data=csv_data, file_name='questions.csv', mime='text/csv')
|
|
|
|
|
|
|
147 |
|
148 |
+
pdf_data = export_to_pdf(data)
|
149 |
+
st.download_button(label="PDF Format", data=pdf_data, file_name='questions.pdf', mime='application/pdf')
|
|
|
|
|
|
|
|
|
|
|
150 |
|
151 |
else:
|
152 |
st.write("Please enter some text to generate questions.")
|