Spaces:
Running
Running

Refactor summary generation to use Gradio client for TextRank, Luhn, LSA, and LexRank summarizers; improve error handling and logging
c69bbef
from math_summarizer import generate_math_summary | |
from nlp_summarizer import generate_nlp_summary_and_mindmap | |
import openai | |
import dotenv | |
import time | |
import os | |
dotenv.load_dotenv() | |
API_KEY = os.getenv('API_KEY') | |
def create_client(api_key): | |
client = openai.OpenAI( | |
api_key=api_key, | |
base_url="https://glhf.chat/api/openai/v1", | |
) | |
return client | |
def generate_summary(client, corpus): | |
response = {} | |
math_summary = generate_math_summary(corpus) | |
if not math_summary: | |
print("Error generating Math Summary") | |
response['summary_status'] = "error" | |
response['summary'] = None | |
response['mindmap_status'] = "error" | |
response['mindmap'] = None | |
return response | |
else: | |
response = generate_nlp_summary_and_mindmap(client, corpus) | |
return response | |
def main(corpus): | |
start_time = time.time() | |
client = create_client(API_KEY) | |
response = generate_summary(client, corpus) | |
print(f"Total timetaken: {time.time() - start_time} seconds") | |
return response |