Spaces:
Running
Running
Update nlp_processes.py
Browse files- nlp_processes.py +39 -7
nlp_processes.py
CHANGED
@@ -1,5 +1,5 @@
|
|
1 |
from g4f.client import Client
|
2 |
-
from g4f.Provider import RetryProvider, Liaobots,
|
3 |
import threading
|
4 |
|
5 |
def generate_nlp_summary(temp_summary):
|
@@ -8,7 +8,7 @@ def generate_nlp_summary(temp_summary):
|
|
8 |
client = Client()
|
9 |
completion = client.chat.completions.create(
|
10 |
provider=RetryProvider(
|
11 |
-
providers=[Liaobots,
|
12 |
shuffle=True,
|
13 |
max_retries=6,
|
14 |
),
|
@@ -31,8 +31,24 @@ def generate_nlp_summary(temp_summary):
|
|
31 |
)
|
32 |
return completion.choices[0].message.content.replace("**", "").replace("\n\n", "\n").replace("\n \n", "\n").replace("##", "\n##").strip()
|
33 |
except Exception as e:
|
34 |
-
|
35 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
36 |
|
37 |
def generate_nlp_mindmap(temp_summary):
|
38 |
try:
|
@@ -40,7 +56,7 @@ def generate_nlp_mindmap(temp_summary):
|
|
40 |
client = Client()
|
41 |
completion = client.chat.completions.create(
|
42 |
provider=RetryProvider(
|
43 |
-
providers=[Liaobots,
|
44 |
shuffle=True,
|
45 |
max_retries=6,
|
46 |
),
|
@@ -63,8 +79,24 @@ def generate_nlp_mindmap(temp_summary):
|
|
63 |
)
|
64 |
return completion.choices[0].message.content.replace("**", "").replace("\n\n", "\n").replace("\n \n", "\n").replace("##", "\n##").strip()
|
65 |
except Exception as e:
|
66 |
-
|
67 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
68 |
|
69 |
def generate_nlp_summary_and_mindmap(temp_summary):
|
70 |
response = {}
|
|
|
1 |
from g4f.client import Client
|
2 |
+
from g4f.Provider import RetryProvider, Liaobots, PollinationsAI, Blackbox, DDG, DeepInfraChat, Jmuz
|
3 |
import threading
|
4 |
|
5 |
def generate_nlp_summary(temp_summary):
|
|
|
8 |
client = Client()
|
9 |
completion = client.chat.completions.create(
|
10 |
provider=RetryProvider(
|
11 |
+
providers=[Liaobots, PollinationsAI],
|
12 |
shuffle=True,
|
13 |
max_retries=6,
|
14 |
),
|
|
|
31 |
)
|
32 |
return completion.choices[0].message.content.replace("**", "").replace("\n\n", "\n").replace("\n \n", "\n").replace("##", "\n##").strip()
|
33 |
except Exception as e:
|
34 |
+
try:
|
35 |
+
client = Client()
|
36 |
+
completion = client.chat.completions.create(
|
37 |
+
provider=RetryProvider(
|
38 |
+
providers=[PollinationsAI, Blackbox, DDG, DeepInfraChat, Jmuz],
|
39 |
+
shuffle=True,
|
40 |
+
max_retries=6,
|
41 |
+
),
|
42 |
+
model="llama-3.3-70b",
|
43 |
+
messages=[
|
44 |
+
{"role": "system", "content": "You are a helpful research assistant for generating well-formatted summaries from scientific research papers."},
|
45 |
+
{"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\"'}
|
46 |
+
],
|
47 |
+
)
|
48 |
+
return completion.choices[0].message.content.replace("**", "").replace("\n\n", "\n").replace("\n \n", "\n").replace("##", "\n##").strip()
|
49 |
+
except Exception as e:
|
50 |
+
print(str(e))
|
51 |
+
return False
|
52 |
|
53 |
def generate_nlp_mindmap(temp_summary):
|
54 |
try:
|
|
|
56 |
client = Client()
|
57 |
completion = client.chat.completions.create(
|
58 |
provider=RetryProvider(
|
59 |
+
providers=[Liaobots, PollinationsAI],
|
60 |
shuffle=True,
|
61 |
max_retries=6,
|
62 |
),
|
|
|
79 |
)
|
80 |
return completion.choices[0].message.content.replace("**", "").replace("\n\n", "\n").replace("\n \n", "\n").replace("##", "\n##").strip()
|
81 |
except Exception as e:
|
82 |
+
try:
|
83 |
+
client = Client()
|
84 |
+
completion = client.chat.completions.create(
|
85 |
+
provider=RetryProvider(
|
86 |
+
providers=[PollinationsAI, Blackbox, DDG, DeepInfraChat, Jmuz],
|
87 |
+
shuffle=True,
|
88 |
+
max_retries=6,
|
89 |
+
),
|
90 |
+
model="llama-3.3-70b",
|
91 |
+
messages=[
|
92 |
+
{"role": "system", "content": "You are a helpful research assistant for generating well-formatted mindmaps from scientific research papers."},
|
93 |
+
{"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.'}
|
94 |
+
],
|
95 |
+
)
|
96 |
+
return completion.choices[0].message.content.replace("**", "").replace("\n\n", "\n").replace("\n \n", "\n").replace("##", "\n##").strip()
|
97 |
+
except Exception as e:
|
98 |
+
print(str(e))
|
99 |
+
return False
|
100 |
|
101 |
def generate_nlp_summary_and_mindmap(temp_summary):
|
102 |
response = {}
|