kittendev commited on
Commit
da78f82
·
verified ·
1 Parent(s): 49a5da7

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +49 -5
app.py CHANGED
@@ -1,6 +1,8 @@
 
 
1
  from langchain_google_genai import ChatGoogleGenerativeAI
2
  from langchain_core.messages import HumanMessage, SystemMessage
3
- import gradio as gr
4
 
5
  import tensorflow as tf
6
  from tensorflow import keras
@@ -18,7 +20,7 @@ with open('class_names.json', 'r') as class_name:
18
  llm = ChatGoogleGenerativeAI(model="gemini-1.5-pro-latest", convert_system_message_to_human=True)
19
 
20
 
21
- def get_info(img):
22
  img = img.resize((224, 224), resample=Image.NEAREST)
23
  img_array = keras.utils.img_to_array(img)
24
  img_array = tf.expand_dims(img_array, 0)
@@ -65,21 +67,63 @@ def get_info(img):
65
  f'Penyebaran'
66
  f'Jadikan struktur diatas menjadi default untuk output dari species burung dan selalu '
67
  f'gunakan struktur ini tanpa perlu markdown'
 
 
 
 
 
 
 
68
  f'Jangan tambahkan simbol sebagain pembeda judul dan sub-judul dengan teks biasa'
69
  f'Tambahkan Referensi darimana informasi didapatkan dalam bentuk journal, website '
70
  f'atau referensi manapun, gunakan formatting seperti mendeley untuk referensi'),
71
  HumanMessage(content=f'Berikan informasi taksonomi, habitat, Populasi, Tingkah Laku, dan Penyebaran '
72
- f'mengenai burung {species}'),
73
  ]
74
  )
75
  return result.content
76
 
77
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
78
  demo = gr.Interface(
79
  fn=get_info,
80
- inputs=gr.Image(type="pil"),
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
81
  outputs=['text'],
82
- allow_flagging="never"
 
 
 
83
  )
84
 
85
  demo.launch()
 
1
+ import gradio as gr
2
+
3
  from langchain_google_genai import ChatGoogleGenerativeAI
4
  from langchain_core.messages import HumanMessage, SystemMessage
5
+
6
 
7
  import tensorflow as tf
8
  from tensorflow import keras
 
20
  llm = ChatGoogleGenerativeAI(model="gemini-1.5-pro-latest", convert_system_message_to_human=True)
21
 
22
 
23
+ def get_info(language, img):
24
  img = img.resize((224, 224), resample=Image.NEAREST)
25
  img_array = keras.utils.img_to_array(img)
26
  img_array = tf.expand_dims(img_array, 0)
 
67
  f'Penyebaran'
68
  f'Jadikan struktur diatas menjadi default untuk output dari species burung dan selalu '
69
  f'gunakan struktur ini tanpa perlu markdown'
70
+ f'Jika jenis burung bukan merupakan spesies spesifik, '
71
+ f'berikan informasi umum mengenai burung dan '
72
+ f'pada kolom species berikan setiap species yang termasuk dalam jenis burung tersebut'
73
+ f'lalu pada nama spesies burung, '
74
+ f'berikan nama latin untuk genus saja. Kasuari (Casuarius). '
75
+ f'Nama burung disesuaikan dengan bahasa yang dipilih oleh pengguna, jika pengguna '
76
+ f'memilih bahasa indonesia, maka nama burung harus disesuaikan dengan bahasa indonesia'
77
  f'Jangan tambahkan simbol sebagain pembeda judul dan sub-judul dengan teks biasa'
78
  f'Tambahkan Referensi darimana informasi didapatkan dalam bentuk journal, website '
79
  f'atau referensi manapun, gunakan formatting seperti mendeley untuk referensi'),
80
  HumanMessage(content=f'Berikan informasi taksonomi, habitat, Populasi, Tingkah Laku, dan Penyebaran '
81
+ f'mengenai burung {species} menggunakan bahasa {language}'),
82
  ]
83
  )
84
  return result.content
85
 
86
 
87
+ title = "Aviary Vision"
88
+ description = """
89
+ <div style="display: flex; flex-direction: column; align-items: center;">
90
+ <h1 style="margin: 0; font-size: 60px;">Aviary Vision</h1>
91
+ <p style="margin: 0; font-size: 20px;">By: A2 Si Paling Data</p>
92
+ </div>
93
+ <p>Aviary Vision is a system that can identify bird species from an image and provide
94
+ information about the species in the selected language.</p>
95
+ <i>Note: The information provided is AI generated and may not be accurate. Use at your own risk.</i>
96
+ """
97
+ examples = [
98
+ ['English', 'bali_starling.png'],
99
+ ['Bahasa Indonesia', 'cassowary.png']
100
+ ]
101
+
102
  demo = gr.Interface(
103
  fn=get_info,
104
+ inputs=[
105
+ gr.Dropdown(choices=[
106
+ 'English',
107
+ 'Bahasa Indonesia',
108
+ '日本語',
109
+ '中文',
110
+ '한국어',
111
+ 'Español',
112
+ 'Français',
113
+ 'Deutsch',
114
+ 'Русский'
115
+ ],
116
+ label="Select Language",
117
+ type="value",
118
+ info="Select the language you want to use"),
119
+ gr.Image(type="pil",
120
+ label="Upload Image")
121
+ ],
122
  outputs=['text'],
123
+ allow_flagging="never",
124
+ title=title,
125
+ description=description,
126
+ examples=examples,
127
  )
128
 
129
  demo.launch()