import gradio as gr import anthropic client = anthropic.Anthropic() SYSTEM_PROMPT = """You are a smart notes simplifier. When given any text, you must follow these strict rules: 1. ✅ Convert everything into SIMPLE, EASY English (like explaining to a 12-year-old) 2. ✅ Write SHORT bullet points only — max 1-2 sentences each 3. ✅ Keep ONLY the important information — remove filler, repetition, and unnecessary details 4. ✅ REMOVE all difficult, technical, or complex words — replace them with simple everyday words 5. ✅ NEVER copy the original sentences — always rewrite completely in your own words 6. ✅ Format output as a clean bullet list using the • symbol 7. ✅ Start directly with bullet points — no intro, no conclusion, no extra commentary Be concise. Aim for 5–12 bullet points depending on the length of the content.""" def simplify_notes(text): if not text or not text.strip(): return "⚠️ Please paste some notes or text first." try: message = client.messages.create( model="claude-opus-4-5", max_tokens=1024, system=SYSTEM_PROMPT, messages=[ {"role": "user", "content": f"Simplify these notes:\n\n{text}"} ] ) return message.content[0].text except anthropic.AuthenticationError: return "❌ API key error. Please check your ANTHROPIC_API_KEY in Space secrets." except anthropic.RateLimitError: return "⚠️ Rate limit reached. Please wait a moment and try again." except Exception as e: return f"❌ Something went wrong: {str(e)}" # --- UI --- with gr.Blocks( title="Notes Simplifier", theme=gr.themes.Soft( primary_hue="teal", secondary_hue="green", font=[gr.themes.GoogleFont("DM Sans"), "sans-serif"], ), css=""" #title { text-align: center; margin-bottom: 4px; } #subtitle { text-align: center; color: #666; margin-bottom: 20px; font-size: 15px; } .tag { display: inline-block; background: #e0f2f1; color: #00695c; padding: 3px 10px; border-radius: 20px; font-size: 13px; margin: 2px; } #tags { text-align: center; margin-bottom: 24px; } footer { display: none !important; } """ ) as demo: gr.Markdown("# 📝 Notes Simplifier", elem_id="title") gr.Markdown("Paste any complex notes → get clean, simple bullet points instantly", elem_id="subtitle") gr.HTML("""
✅ Simple English ✅ Bullet Points ✅ Key Info Only ✅ No Hard Words ✅ Rewritten Fresh
""") with gr.Row(): with gr.Column(): input_text = gr.Textbox( label="📄 Your Original Notes", placeholder="Paste your complex notes, lecture text, article, or any paragraph here...", lines=14, max_lines=30, ) with gr.Row(): clear_btn = gr.Button("🗑️ Clear", variant="secondary", scale=1) simplify_btn = gr.Button("✨ Simplify Notes", variant="primary", scale=3) with gr.Column(): output_text = gr.Textbox( label="✅ Simplified Summary", placeholder="Your simplified bullet points will appear here...", lines=14, max_lines=30, show_copy_button=True, ) # Example inputs gr.Examples( examples=[ ["The mitochondria are membrane-bound organelles found in the cytoplasm of eukaryotic cells that generate most of the cell's supply of adenosine triphosphate (ATP), used as a source of chemical energy. In addition to supplying cellular energy, mitochondria are involved in other tasks, such as signaling, cellular differentiation, and cell death, as well as maintaining control of the cell cycle and cell growth."], ["Photosynthesis is a process used by plants and other organisms to convert light energy into chemical energy that, through cellular respiration, can later be released to fuel the organism's activities. Some of this chemical energy is stored in carbohydrate molecules, such as sugars and starches, which are synthesized from carbon dioxide and water – hence the name photosynthesis, from the Greek phōs (φῶς), 'light', and synthesis (σύνθεσις), 'putting together'."], ["The French Revolution was a period of radical political and societal change in France that began with the Estates General of 1789 and ended with the formation of the French Consulate in November 1799. Many of its ideas are considered fundamental principles of liberal democracy, while the Revolution is also credited as a defining moment in Western civilization that continues to have a major impact on world history."], ], inputs=input_text, label="💡 Try an Example" ) # Events simplify_btn.click(fn=simplify_notes, inputs=input_text, outputs=output_text) clear_btn.click(fn=lambda: ("", ""), outputs=[input_text, output_text]) if __name__ == "__main__": demo.launch()