raannakasturi commited on
Commit
d0808a2
·
1 Parent(s): 626034e

Update API base URL and enhance NLP summary generation

Browse files
Files changed (2) hide show
  1. main.py +1 -1
  2. nlp_summarizer.py +11 -6
main.py CHANGED
@@ -14,7 +14,7 @@ ACCESS_KEY = os.getenv("ACCESS_KEY")
14
  def create_client(api_key):
15
  client = openai.OpenAI(
16
  api_key=api_key,
17
- base_url="https://glhf.chat/api/openai/v1",
18
  )
19
  return client
20
 
 
14
  def create_client(api_key):
15
  client = openai.OpenAI(
16
  api_key=api_key,
17
+ base_url="https://api.groq.com/openai/v1",
18
  )
19
  return client
20
 
nlp_summarizer.py CHANGED
@@ -1,30 +1,34 @@
1
  import threading
2
 
3
  def generate_nlp_summary(client, temp_summary):
 
4
  try:
5
  completion = client.chat.completions.create(
6
- model="hf:meta-llama/Meta-Llama-3.1-405B-Instruct",
7
  messages=[
8
  {"role": "system", "content": "You are a helpful research assistant for generating well-formatted summaries from scientific research papers."},
9
  {"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\"'}
10
  ]
11
  )
 
12
  return completion.choices[0].message.content
13
  except Exception as e:
14
  return False
15
 
16
  def generate_nlp_mindmap(client, temp_summary):
17
- try:
 
18
  completion = client.chat.completions.create(
19
- model="hf:meta-llama/Meta-Llama-3.1-405B-Instruct",
20
  messages=[
21
  {"role": "system", "content": "You are a helpful research assistant for generating well-formatted mindmaps from scientific research papers."},
22
  {"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.'}
23
  ]
24
  )
 
25
  return completion.choices[0].message.content
26
- except Exception as e:
27
- return False
28
 
29
  def generate_nlp_summary_and_mindmap(client, temp_summary):
30
  response = {}
@@ -51,4 +55,5 @@ def generate_nlp_summary_and_mindmap(client, temp_summary):
51
  thread.start()
52
  for thread in threads:
53
  thread.join()
54
- return response
 
 
1
  import threading
2
 
3
  def generate_nlp_summary(client, temp_summary):
4
+ print("Generating NLP Summary")
5
  try:
6
  completion = client.chat.completions.create(
7
+ model="llama-3.2-90b-vision-preview",
8
  messages=[
9
  {"role": "system", "content": "You are a helpful research assistant for generating well-formatted summaries from scientific research papers."},
10
  {"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\"'}
11
  ]
12
  )
13
+ print(completion.choices[0].message.content)
14
  return completion.choices[0].message.content
15
  except Exception as e:
16
  return False
17
 
18
  def generate_nlp_mindmap(client, temp_summary):
19
+ print("Generating Mindmap")
20
+ # try:
21
  completion = client.chat.completions.create(
22
+ model="llama-3.2-90b-vision-preview",
23
  messages=[
24
  {"role": "system", "content": "You are a helpful research assistant for generating well-formatted mindmaps from scientific research papers."},
25
  {"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.'}
26
  ]
27
  )
28
+ print(completion.choices[0].message.content)
29
  return completion.choices[0].message.content
30
+ # except Exception as e:
31
+ # return False
32
 
33
  def generate_nlp_summary_and_mindmap(client, temp_summary):
34
  response = {}
 
55
  thread.start()
56
  for thread in threads:
57
  thread.join()
58
+ return response
59
+