Spaces:
Running
Running
File size: 4,176 Bytes
be7c65c afe5f52 be7c65c afe5f52 be7c65c afe5f52 be7c65c afe5f52 be7c65c afe5f52 6e23a32 afe5f52 be7c65c afe5f52 be7c65c 147a16a be7c65c afe5f52 be7c65c afe5f52 be7c65c afe5f52 6e23a32 147a16a be7c65c 147a16a afe5f52 be7c65c afe5f52 be7c65c afe5f52 6e23a32 afe5f52 be7c65c afe5f52 6e23a32 afe5f52 d0808a2 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
from g4f.client import Client
from g4f.Provider import RetryProvider, Blackbox, MetaAI
import threading
def generate_nlp_summary(temp_summary):
try:
client = Client(
provider=RetryProvider(
providers=[Blackbox, MetaAI],
shuffle=True,
single_provider_retry=True,
max_retries=3,
),
)
completion = client.chat.completions.create(
model="llama-3.1-405b",
messages=[
{"role": "system", "content": "You are a helpful research assistant for generating well-formatted summaries from scientific research papers."},
{"role": "user", "content": f'As a text script expert, please help me to write a short text script with the topic \" {temp_summary}\".You have three tasks, which are:\\n 1.to summarize the text I provided into a Summary .Please answer within 150-300 characters.\\n 2.to summarize the text I provided, using up to seven Highlight.\\n 3.to summarize the text I provided, using up to seven Key Insights. Each insight should include a brief in-depth analysis. Key Insight should not include timestamps.\\n Your output should use the following template strictly, provide the results for the three tasks:\\n ## Summary\\n ## Highlights\\n - Highlights\\n ## Key Insights\\n - Key Insights .\\n Importantly your output must use language \"English\"'}
],
)
return completion.choices[0].message.content.replace("**", "").replace("\n\n", "\n").replace("\n \n", "\n").replace("##", "\n##").strip()
except Exception as e:
print(str(e))
return False
def generate_nlp_mindmap(temp_summary):
try:
client = Client(
provider=RetryProvider(
providers=[Blackbox, MetaAI],
shuffle=True,
single_provider_retry=True,
max_retries=3,
),
)
completion = client.chat.completions.create(
model="llama-3.1-405b",
messages=[
{"role": "system", "content": "You are a helpful research assistant for generating well-formatted mindmaps from scientific research papers."},
{"role": "user", "content": f'As a text script expert, please help me to write a short text script with the topic \"{temp_summary}\".Your output should use the following template:\\n\\n## {{Subtitle01}}\\n- {{Bulletpoint01}}\\n- {{Bulletpoint02}}\\n## {{Subtitle02}}\\n- {{Bulletpoint03}}\\n- {{Bulletpoint04}}\\n\\nSummarize the giving topic to generate a mind map (as many subtitles as possible, with a minimum of three subtitles) structure markdown. Do not include anything in the response, that is not the part of mindmap.\\n Most Importantly your output must use language \"English\" and each point or pointer should include no more than 9 words.'}
],
)
return completion.choices[0].message.content.replace("**", "").replace("\n\n", "\n").replace("\n \n", "\n").replace("##", "\n##").strip()
except Exception as e:
print(str(e))
return False
def generate_nlp_summary_and_mindmap(temp_summary):
response = {}
def local_generate_nlp_summary():
nlp_summary = generate_nlp_summary(temp_summary)
if not nlp_summary:
response["summary_status"] = "error"
response["summary"] = None
else:
response["summary_status"] = "success"
response["summary"] = nlp_summary.strip()
def local_generate_nlp_mindmap():
nlp_mindmap = generate_nlp_mindmap(temp_summary)
if not nlp_mindmap:
response["mindmap_status"] = "error"
response["mindmap"] = None
else:
response["mindmap_status"] = "success"
response["mindmap"] = nlp_mindmap.strip()
threads = []
threads.append(threading.Thread(target=local_generate_nlp_summary))
threads.append(threading.Thread(target=local_generate_nlp_mindmap))
for thread in threads:
thread.start()
for thread in threads:
thread.join()
return response
|