|
from TempSummary import generate_temp_summary |
|
import time |
|
|
|
def generate_summary(llm, file): |
|
print("Generating temporary summary...") |
|
temp_summary, length_of_research_paper = generate_temp_summary(file) |
|
print("Temporary summary generated successfully") |
|
print("Generating final summary...") |
|
prompt = f"As a text script expert, please help me to write a short text script with the research paper \"{temp_summary}\".You have three tasks, which are:\\n 1.to summarize the text I provided into a Summary . Please answer within 200-300 characters.\\n 2.to summarize the text I provided, using up to seven concise Highlights. Choose appropriate emoji for each Highlight.\\n 3.to summarize the text I provided, using up to seven Key Insights. Each insight should include a brief in-depth analysis. Choose appropriate emoji for each key insights. Using the following template strictly, provide the results for the three tasks:\\n ### Summary\\n ### Highlights -[emoji]\\n ### key Insights -[emoji] .\\n Importantly your output must use language \"English\"\"" |
|
response = llm.create_chat_completion( |
|
messages = [ |
|
{'role':'system', |
|
'content': 'You are a helpful research assistant for generating well-formatted summaries from scientific research papers.'}, |
|
{'role':'user', |
|
'content': prompt} |
|
], |
|
temperature=0.5, |
|
top_k=200, |
|
top_p=3.0, |
|
) |
|
summary = response['choices'][0]['message']['content'] |
|
return summary, length_of_research_paper |
|
|
|
def summarize(llm, file): |
|
import time |
|
start_time = time.time() |
|
response, length_of_research_paper = generate_summary(llm, file) |
|
if "**" in response: |
|
response = response.replace("- **", "### ") |
|
response = response.replace("**", "") |
|
response = response.replace("\n\n", "\n") |
|
response = response.replace("\\n\\n", "\\n") |
|
summary = "" |
|
for line in response.splitlines(): |
|
if line.startswith("###"): |
|
summary += "\n\n" + line |
|
else: |
|
summary += "\n" + line |
|
end_time = time.time() |
|
total_time_taken = end_time - start_time |
|
total_time_taken_minutes = round(total_time_taken / 60, 3) |
|
info = f"The research paper of {length_of_research_paper} characters long was summarized in {total_time_taken_minutes} minutes." |
|
print(info) |
|
return summary.strip(), info |
|
|