LN34 commited on
Commit
6b5eff1
·
verified ·
1 Parent(s): 83fb91a

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +34 -0
app.py ADDED
@@ -0,0 +1,34 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ import gradio as gr
3
+ from groq import Groq
4
+
5
+ # Load API key from Hugging Face Secrets
6
+ api_key = os.getenv("GROQ_API_KEY")
7
+ if not api_key:
8
+ raise ValueError("Missing GROQ_API_KEY. Please set it in Hugging Face Space Settings → Secrets.")
9
+
10
+ client = Groq(api_key=api_key)
11
+
12
+ def summarize_abstract(text):
13
+ try:
14
+ response = client.chat.completions.create(
15
+ model="openai/gpt-oss-120b", # 🔑 replace with a valid model from client.models.list()
16
+ messages=[
17
+ {"role": "system", "content": "You are a scientific assistant that summarizes abstracts into 3–4 sentences."},
18
+ {"role": "user", "content": text}
19
+ ],
20
+ max_tokens=250
21
+ )
22
+ return response.choices[0].message.content
23
+ except Exception as e:
24
+ return f"Error: {str(e)}"
25
+
26
+ demo = gr.Interface(
27
+ fn=summarize_abstract,
28
+ inputs=gr.Textbox(lines=10, label="Paste Abstract"),
29
+ outputs="text",
30
+ title="📄 Scientific Abstract Summarizer",
31
+ description="Paste a scientific abstract and get a concise summary."
32
+ )
33
+
34
+ demo.launch()