raannakasturi commited on
Commit
67ffe93
·
verified ·
1 Parent(s): 5f2c1c3

Update main.py

Browse files
Files changed (1) hide show
  1. main.py +40 -37
main.py CHANGED
@@ -1,38 +1,41 @@
1
- from math_summarizer import generate_math_summary
2
- from nlp_summarizer import generate_nlp_summary_and_mindmap
3
- import openai
4
- import dotenv
5
- import os
6
-
7
- dotenv.load_dotenv()
8
- API_KEY = os.getenv('API_KEY')
9
-
10
- def create_client(api_key):
11
- client = openai.OpenAI(
12
- api_key=api_key,
13
- base_url="https://glhf.chat/api/openai/v1",
14
- )
15
- return client
16
-
17
- def generate_summary(client, corpus):
18
- response = {}
19
- print("Generating Math Summary")
20
- math_summary = generate_math_summary(corpus)
21
- if not math_summary:
22
- print("Error generating Math Summary")
23
- response['summary_status'] = "error"
24
- response['summary'] = None
25
- response['mindmap_status'] = "success"
26
- response['mindmap'] = None
27
- return response
28
- else:
29
- print("Math Summary Generated Successfully")
30
- print("Generating NLP Summary and Mindmap")
31
- response = generate_nlp_summary_and_mindmap(client, corpus)
32
- print("NLP Summary and Mindmap Generated Successfully")
33
- return response
34
-
35
- def main(corpus):
36
- client = create_client(API_KEY)
37
- response = generate_summary(client, corpus)
 
 
 
38
  return response
 
1
+ from math_summarizer import generate_math_summary
2
+ from nlp_summarizer import generate_nlp_summary_and_mindmap
3
+ import openai
4
+ import dotenv
5
+ import time
6
+ import os
7
+
8
+ dotenv.load_dotenv()
9
+ API_KEY = os.getenv('API_KEY')
10
+
11
+ def create_client(api_key):
12
+ client = openai.OpenAI(
13
+ api_key=api_key,
14
+ base_url="https://glhf.chat/api/openai/v1",
15
+ )
16
+ return client
17
+
18
+ def generate_summary(client, corpus):
19
+ response = {}
20
+ print("Generating Math Summary")
21
+ math_summary = generate_math_summary(corpus)
22
+ if not math_summary:
23
+ print("Error generating Math Summary")
24
+ response['summary_status'] = "error"
25
+ response['summary'] = None
26
+ response['mindmap_status'] = "success"
27
+ response['mindmap'] = None
28
+ return response
29
+ else:
30
+ print("Math Summary Generated Successfully")
31
+ print("Generating NLP Summary and Mindmap")
32
+ response = generate_nlp_summary_and_mindmap(client, corpus)
33
+ print("NLP Summary and Mindmap Generated Successfully")
34
+ return response
35
+
36
+ def main(corpus):
37
+ start_time = time.time()
38
+ client = create_client(API_KEY)
39
+ response = generate_summary(client, corpus)
40
+ print(f"Total timetaken: {time.time() - start_time} seconds")
41
  return response