File size: 2,210 Bytes
133fefa
 
 
 
 
 
cd8d630
51179ad
e7c5b52
133fefa
51179ad
e7c5b52
e249ab2
92c4488
 
 
51179ad
e249ab2
92c4488
a425de0
e7c5b52
 
 
51179ad
e7c5b52
51179ad
a425de0
e7c5b52
 
a425de0
 
e7c5b52
 
a425de0
 
e7c5b52
 
a425de0
e7c5b52
92c4488
51179ad
 
92c4488
e7c5b52
92c4488
e7c5b52
 
 
92c4488
e7c5b52
 
92c4488
51179ad
92c4488
 
 
51179ad
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
import streamlit as st
from transformers import pipeline
import nltk
from nltk.tokenize import word_tokenize

# Buat objek terjemahan
translator = pipeline("translation", model="Helsinki-NLP/opus-mt-id-en")
terjemah = pipeline("translation", model="Helsinki-NLP/opus-mt-en-id")
pipe = pipeline("text-generation", model="TinyLlama/TinyLlama-1.1B-Chat-v1.0")

# Antarmuka Streamlit
st.title("Diagnosa Berdasarkan Gejala Kehamilan")

# Masukkan gejala, usia, dan jenis kelamin
usia = st.number_input("Masukkan usia Anda:", min_value=0, max_value=120)
jenis_kelamin = st.selectbox("Masukkan jenis kelamin Anda:", ["Laki-laki", "Perempuan"])
gejala_id = st.text_area("Masukkan gejala Anda:")

if st.button("Diagnosa"):
    if gejala_id:
        # Terjemahkan gejala dari Bahasa Indonesia ke Bahasa Inggris
        gejala_en = translator(gejala_id, max_length=100)[0]["translation_text"]
        informasi_pasien = f"I am {usia} years old, {jenis_kelamin}. Current symptoms are: {gejala_en}"

        # Contoh kasus kehamilan untuk diagnosis
        pesan = [
            {"role": "system",
             "content": """
You are a doctor diagnosing pregnancy-related conditions based on symptoms.

Example 1:
Patient symptoms: Missed period, nausea, tender breasts
Diagnosis: Possible pregnancy

Example 2:
Patient symptoms: Severe abdominal pain, bleeding
Diagnosis: Possible miscarriage or ectopic pregnancy.
"""},
            {"role": "user", "content": f"Based on your assessment, {informasi_pasien}, what is your diagnosis?"}
        ]

        # Fungsi untuk mendapatkan konten dari role 'assistant'
        def get_assistant_content(response):
            return response[0]['generated_text']

        # Dapatkan respon dari pipe
        response = pipe(pesan, num_return_sequences=1, truncation=True)
        diagnosis = get_assistant_content(response)

        # Terjemahkan hasil ke Bahasa Indonesia
        diagnosa_terjemahan = terjemah(diagnosis, max_length=100)[0]["translation_text"]

        # Tampilkan hasil ke Streamlit
        st.subheader("Hasil Diagnosis:")
        st.write(f"Diagnosis: {diagnosa_terjemahan}")
    else:
        st.error("Harap isi semua kolom sebelum menekan tombol Diagnosa.")