Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -18,8 +18,7 @@ from transformers import pipeline
|
|
18 |
# citation_generator = pipeline("text-generation", model="gpt2")
|
19 |
|
20 |
# from transformers import AutoTokenizer, AutoModelForSeq2SeqLM
|
21 |
-
|
22 |
-
from transformers import T5Tokenizer, T5ForConditionalGeneration
|
23 |
|
24 |
|
25 |
def search_related_articles_crossref(query, max_results=3):
|
@@ -65,9 +64,9 @@ def extract_text_from_html(url):
|
|
65 |
except Exception as e:
|
66 |
return f"Error extracting text: {str(e)}"
|
67 |
|
68 |
-
|
69 |
-
tokenizer =
|
70 |
-
model =
|
71 |
|
72 |
def summarize_article(article_text):
|
73 |
"""Summarize a given article's text."""
|
@@ -187,11 +186,11 @@ def research_assistant(research_topic, citation_style):
|
|
187 |
# Fetching article content might not be feasible; consider using metadata
|
188 |
article_content += f"{extract_text_from_html(article['link'])}.\n" # Simplified; actual content may require other methods
|
189 |
|
190 |
-
|
191 |
-
|
192 |
-
|
193 |
-
|
194 |
-
|
195 |
|
196 |
except Exception as e:
|
197 |
summaries.append(f"Error processing article '{article['title']}': {str(e)}")
|
|
|
18 |
# citation_generator = pipeline("text-generation", model="gpt2")
|
19 |
|
20 |
# from transformers import AutoTokenizer, AutoModelForSeq2SeqLM
|
21 |
+
from transformers import AutoTokenizer, AutoModelForSeq2SeqLM
|
|
|
22 |
|
23 |
|
24 |
def search_related_articles_crossref(query, max_results=3):
|
|
|
64 |
except Exception as e:
|
65 |
return f"Error extracting text: {str(e)}"
|
66 |
|
67 |
+
# Load the tokenizer and model
|
68 |
+
tokenizer = AutoTokenizer.from_pretrained("pszemraj/pegasus-large-summary-explain")
|
69 |
+
model = AutoModelForSeq2SeqLM.from_pretrained("pszemraj/pegasus-large-summary-explain")
|
70 |
|
71 |
def summarize_article(article_text):
|
72 |
"""Summarize a given article's text."""
|
|
|
186 |
# Fetching article content might not be feasible; consider using metadata
|
187 |
article_content += f"{extract_text_from_html(article['link'])}.\n" # Simplified; actual content may require other methods
|
188 |
|
189 |
+
citation, error = generate_citation_t5(article['title'], citation_style, article['link'])
|
190 |
+
if error:
|
191 |
+
citations.append(f"Error generating citation for '{article['title']}': {error}")
|
192 |
+
else:
|
193 |
+
citations.append(citation)
|
194 |
|
195 |
except Exception as e:
|
196 |
summaries.append(f"Error processing article '{article['title']}': {str(e)}")
|