Spaces:
Sleeping
Sleeping
File size: 1,620 Bytes
6b5eff1 58ebe8b 6b5eff1 58ebe8b 6b5eff1 58ebe8b 6b5eff1 58ebe8b 6b5eff1 58ebe8b 6b5eff1 58ebe8b 6b5eff1 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 | import os
import gradio as gr
from groq import Groq
api_key = os.getenv("GROQ_API_KEY")
if not api_key:
raise ValueError("Missing GROQ_API_KEY. Please set it in Hugging Face Space Settings → Secrets.")
client = Groq(api_key=api_key)
def summarize_abstract(text):
try:
response = client.chat.completions.create(
model="openai/gpt-oss-120b", # replace with a valid model from client.models.list()
messages=[
{"role": "system", "content": "Summarize the abstract into two parts: Main Idea and Findings."},
{"role": "user", "content": text}
],
max_tokens=250
)
summary = response.choices[0].message.content
# Simple parsing: look for "Main Idea:" and "Findings:"
main_html, findings_html = "", ""
for line in summary.split("\n"):
if line.lower().startswith("main idea"):
main_html = f"<span style='color:pink; font-weight:bold'>{line}</span>"
elif line.lower().startswith("findings"):
findings_html = f"<span style='color:gold; font-weight:bold'>{line}</span>"
return main_html + "<br>" + findings_html if (main_html or findings_html) else summary
except Exception as e:
return f"<span style='color:red'>Error: {str(e)}</span>"
demo = gr.Interface(
fn=summarize_abstract,
inputs=gr.Textbox(lines=10, label="Paste Abstract"),
outputs=gr.HTML(label="Summary"),
title="📄 Scientific Abstract Summarizer",
description="Main Idea appears in pink, Findings in yellow."
)
demo.launch()
|