from gradio_client import Client import threading def generate_textrank_summary(research_paper_text): client = Client("raannakasturi/TextRankSummarizer") summary = client.predict( text_corpus=research_paper_text, api_name="/textrank_summarizer" ) return summary def generate_luhn_summary(research_paper_text): client = Client("raannakasturi/LuhnSummarizer") summary = client.predict( text_corpus=research_paper_text, api_name="/luhn_summarizer" ) return summary def sanitize_text(input_string): try: encoded_bytes = input_string.encode("utf-8") decoded_string = encoded_bytes.decode("utf-8") return decoded_string except UnicodeEncodeError as e: print(f"Encoding error: {e}") raise except UnicodeDecodeError as e: print(f"Decoding error: {e}") raise def generate_math_summary(research_paper_text): sanitized_text = sanitize_text(research_paper_text) try: textrank_summary = luhn_summary = None def run_textrank(): nonlocal textrank_summary textrank_summary = generate_textrank_summary(sanitized_text) def run_luhn(): nonlocal luhn_summary luhn_summary = generate_luhn_summary(sanitized_text) threads = [] threads.append(threading.Thread(target=run_textrank)) threads.append(threading.Thread(target=run_luhn)) for thread in threads: thread.start() for thread in threads: thread.join() math_summary = textrank_summary.replace("\n", "") + luhn_summary.replace("\n", "") return math_summary except Exception as e: print(e) return False