Spaces:
Sleeping
Sleeping
| import gradio as gr | |
| from datetime import datetime | |
| from db.database import init_db | |
| from utils.subscription import get_subscription | |
| from utils.payments import create_payment | |
| from utils.ai_engine import generate_soap, medical_chat | |
| from utils.notifications import add_notification, get_notifications | |
| USER_ID = 1 | |
| init_db() | |
| def create_soap(s, o, a, p): | |
| if get_subscription(USER_ID) == "Free": | |
| return "❌ Free plan limit reached. Upgrade to Pro." | |
| return generate_soap(s, o, a, p) | |
| def pay(amount): | |
| ref = f"TB{int(datetime.now().timestamp())}" | |
| create_payment(USER_ID, amount, "Telebirr", ref) | |
| add_notification(f"Payment successful: {amount} ETB") | |
| return f"Payment successful. Ref: {ref}" | |
| with gr.Blocks() as demo: | |
| gr.Markdown("## 🏥 Selam Health AI (Stable Core)") | |
| with gr.Tab("SOAP"): | |
| s = gr.Textbox(label="Subjective") | |
| o = gr.Textbox(label="Objective") | |
| a = gr.Textbox(label="Assessment") | |
| p = gr.Textbox(label="Plan") | |
| out = gr.Textbox(lines=10) | |
| gr.Button("Generate").click(create_soap, [s, o, a, p], out) | |
| with gr.Tab("Chat"): | |
| chat = gr.Chatbot() | |
| msg = gr.Textbox() | |
| gr.Button("Send").click( | |
| lambda m, h: (h + [[m, medical_chat(m)]], h + [[m, medical_chat(m)]]), | |
| [msg, chat], | |
| [chat, chat] | |
| ) | |
| with gr.Tab("Payment"): | |
| amt = gr.Number(label="Amount (ETB)") | |
| pay_out = gr.Textbox() | |
| gr.Button("Pay").click(pay, amt, pay_out) | |
| with gr.Tab("Notifications"): | |
| n = gr.Textbox(lines=10) | |
| gr.Button("Refresh").click(get_notifications, [], n) | |
| demo.launch() |