Spaces:
Sleeping
Sleeping
Download app.py from LN34/ScientificAbstractSummarizer: direct link, hf CLI and curl.
- Browser
- Download file 1.62 kB
-
https://huggingface.co/spaces/LN34/ScientificAbstractSummarizer/resolve/main/app.py
- Command line
-
hf download hf://spaces/LN34/ScientificAbstractSummarizer/app.py
-
curl -L -o app.py https://huggingface.co/spaces/LN34/ScientificAbstractSummarizer/resolve/main/app.py
1.62 kB
| 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() | |