File size: 2,960 Bytes
795d2e3
aed6b91
795d2e3
 
aed6b91
795d2e3
8b93173
3160578
 
8f7408c
 
 
 
 
6e2754a
56db06a
e184596
aed6b91
 
 
 
 
 
 
8b93173
aed6b91
 
 
 
 
 
 
 
8b93173
 
 
 
 
 
3160578
 
670570b
e184596
56db06a
795d2e3
29f2166
795d2e3
8d68ac0
8b93173
8d68ac0
6358a38
 
8b93173
795d2e3
6358a38
8d68ac0
 
 
 
6358a38
 
8d68ac0
 
 
 
 
 
795d2e3
 
 
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
import gradio as gr
import requests
import os

API_KEY = os.getenv("OPENROUTER_API_KEY")

def drugexplainer(input_obat, selected_model):
    try:
        prompt = f"""
        Kamu adalah seorang apoteker jenius yang sangat ahli dalam edukasi kesehatan 
        Tugasmu adalah menjelaskan cara kerja obat yang ditanyakan oleh pengguna yang merupakan masyarakat umum
        Patuhi aturan ketat berikut dalam menyusun jawaban:
        1. JANGAN PERNAH menggunakan istilah medis yang rumit
        2. Gunakan gaya bahasa yang sederhana
        Sekarang, jelaskan obat berikut: {input_obat}
        """

        response = requests.post(
            url="https://openrouter.ai/api/v1/chat/completions",
            headers={
                "Authorization": f"Bearer {API_KEY}",
                "Content-Type": "application/json"
            },
            json={
                "model": selected_model,
                "messages": [
                    {"role": "user", "content": prompt}
                ]
            }
        )

        data = response.json()

        # Check if 'choices' key exists and is not empty
        if "choices" in data and len(data["choices"]) > 0:
            return data["choices"][0]["message"]["content"]
        else:
            # Handle cases where 'choices' might be missing or empty
            return f"Error: No content received from the model. Response: {data}"

    except Exception as e:
        return f"Error: {str(e)}"


interface = gr.Interface(
    fn=drugexplainer,
    inputs=[
        gr.Textbox(label="Nama Obat", placeholder="Masukkan nama obat, misal: Omeprazole, Captopril, Metformin..."),
        gr.Dropdown(
            label="Pilih Model AI",
            choices=["baidu/cobuddy:free", "openrouter/owl-alpha", "nvidia/nemotron-3-nano-omni-30b-a3b-reasoning:free", "arcee-ai/trinity-large-thinking:free", "minimax/minimax-m2.5:free", "liquid/lfm-2.5-1.2b-thinking:free", "qwen/qwen3-next-80b-a3b-instruct:free"],
            value="nvidia/nemotron-3-nano-omni-30b-a3b-reasoning:free"
        )
    ],
    outputs=gr.Textbox(label="Penjelasan Apoteker"),
    title="πŸ’Š Drug Mechanism Explainer πŸ’Š",
    description="""
    <div style='font-family: sans-serif; line-height: 1.5;'>
        <p><strong>Selamat datang di Drug Mechanism Explainer!</strong> 🌟</p>
        <p>Aplikasi ini dirancang khusus untuk menjelaskan mekanisme kerja obat yang rumit menjadi sederhana yang mudah dipahami oleh masyarakat awam.</p>
        <p>Dibuat dalam rangka penyelesaian Project IBM SkillsBuild University Education oleh Munawsa dari Universitas Indonesia.</p>
        <hr style='border: 0; border-top: 1px solid #444; margin: 10px 0;'>
        <p style='font-size: 0.9em; color: #aaa;'>
            πŸ’‘ <strong>Cara Pakai:</strong> Ketik nama obat (generik/merek) ➑️ Pilih model AI cadangan jika respons melambat ➑️ Klik <strong>Submit</strong>.
        </p>
    </div>
    """
)

interface.launch()