Update main.py
Browse files
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
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
response['
|
| 25 |
-
response['
|
| 26 |
-
response['
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
print("
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
|
|
|
|
|
|
|
|
|
| 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
|