dafajudin commited on
Commit
7995d71
β€’
1 Parent(s): 8053f20

add contoh input gambar dan teks

Browse files
Files changed (1) hide show
  1. app.py +25 -31
app.py CHANGED
@@ -9,27 +9,9 @@ import torch
9
  from peft import LoraConfig
10
  from transformers import AutoProcessor, BitsAndBytesConfig, IdeficsForVisionText2Text
11
 
12
- # Project description
13
- description = """
14
- # Kalbe Farma - Visual Question Answering (VQA) for Medical Imaging
15
-
16
- ## Overview
17
- The project addresses the challenge of accurate and efficient medical imaging analysis in healthcare, aiming to reduce human error and workload for radiologists. The proposed solution involves developing advanced AI models for Visual Question Answering (VQA) to assist healthcare professionals in analyzing medical images quickly and accurately. These models will be integrated into a user-friendly web application, providing a practical tool for real-world healthcare settings.
18
-
19
- ## Dataset
20
- The model is trained using the [Hugging face](https://huggingface.co/datasets/flaviagiammarino/vqa-rad/viewer).
21
-
22
- Reference: [ScienceDirect](https://www.sciencedirect.com/science/article/abs/pii/S0933365723001252)
23
-
24
- ## Model Architecture
25
-
26
- ![Model Architecture](img/Model-Architecture.png)
27
-
28
- Reference: [ScienceDirect](https://www.sciencedirect.com/science/article/abs/pii/S0933365723001252)
29
-
30
- ## Demo
31
- Please select the example below or upload 4 pairs of mammography exam results.
32
- """
33
 
34
  DEVICE = torch.device("cuda")
35
 
@@ -51,14 +33,14 @@ if USE_QLORA or USE_LORA:
51
  bnb_4bit_quant_type="nf4",
52
  bnb_4bit_compute_dtype=torch.float16
53
  )
54
- # Model
 
55
  model = Idefics2ForConditionalGeneration.from_pretrained(
56
- "jihadzakki/idefics2-8b-vqarad-delta",
57
  torch_dtype=torch.float16,
58
  quantization_config=bnb_config
59
  )
60
 
61
-
62
  processor = AutoProcessor.from_pretrained(
63
  "HuggingFaceM4/idefics2-8b",
64
  )
@@ -135,9 +117,7 @@ with gr.Blocks(
135
  secondary_hue=gr.themes.colors.red,
136
  )
137
  ) as VisualQAApp:
138
- gr.Markdown(description, elem_classes="title") # Display the project description
139
-
140
- gr.Markdown("## Demo")
141
 
142
  with gr.Row():
143
  with gr.Column():
@@ -158,9 +138,9 @@ with gr.Blocks(
158
  )
159
 
160
  with gr.Row():
161
- retry_button = gr.Button("Retry")
162
- undo_button = gr.Button("Undo")
163
- clear_button = gr.Button("Clear")
164
 
165
  retry_button.click(
166
  retry_last,
@@ -188,9 +168,23 @@ with gr.Blocks(
188
  outputs=[history_gallery]
189
  )
190
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
191
  with gr.Accordion("Help", open=False):
192
  gr.Markdown("**Upload image**: Select the chest X-ray image you want to analyze.")
193
- gr.Markdown("**Enter your question**: Type the question you have about the image, such as 'Is there any sign of pneumonia?'")
194
  gr.Markdown("**Submit**: Click the submit button to get the prediction from the model.")
195
 
196
  with gr.Accordion("User Preferences", open=False):
 
9
  from peft import LoraConfig
10
  from transformers import AutoProcessor, BitsAndBytesConfig, IdeficsForVisionText2Text
11
 
12
+ # Baca konten HTML dari file index.html
13
+ with open('index.html', encoding='utf-8') as file:
14
+ html_content = file.read()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
15
 
16
  DEVICE = torch.device("cuda")
17
 
 
33
  bnb_4bit_quant_type="nf4",
34
  bnb_4bit_compute_dtype=torch.float16
35
  )
36
+
37
+ # Model yang akan digunakan
38
  model = Idefics2ForConditionalGeneration.from_pretrained(
39
+ # "jihadzakki/idefics2-8b-vqarad-delta",
40
  torch_dtype=torch.float16,
41
  quantization_config=bnb_config
42
  )
43
 
 
44
  processor = AutoProcessor.from_pretrained(
45
  "HuggingFaceM4/idefics2-8b",
46
  )
 
117
  secondary_hue=gr.themes.colors.red,
118
  )
119
  ) as VisualQAApp:
120
+ gr.HTML(html_content) # Display the HTML content
 
 
121
 
122
  with gr.Row():
123
  with gr.Column():
 
138
  )
139
 
140
  with gr.Row():
141
+ retry_button = gr.Button("πŸ”„ Retry")
142
+ undo_button = gr.Button("↩️ Undo")
143
+ clear_button = gr.Button("πŸ—‘οΈ Clear")
144
 
145
  retry_button.click(
146
  retry_last,
 
168
  outputs=[history_gallery]
169
  )
170
 
171
+ gr.Markdown("## Contoh Input dengan Teks")
172
+ with gr.Row():
173
+ with gr.Column():
174
+ gr.Examples(
175
+ examples=[
176
+ ["sample_data/images/Gambar-Otak-Slake.jpg", "What modality is used to take this image?"],
177
+ ["sample_data/images/Gambar-Otak-Slake2.jpg", "Which part of the body does this image belong to?"]
178
+ ],
179
+ inputs=[image_input, question_input],
180
+ outputs=[answer_output, history_state],
181
+ label="Upload image",
182
+ elem_id="Prompt"
183
+ )
184
+
185
  with gr.Accordion("Help", open=False):
186
  gr.Markdown("**Upload image**: Select the chest X-ray image you want to analyze.")
187
+ gr.Markdown("**Enter your question**: Type the question you have about the image, such as 'What modality is used to take this image?'")
188
  gr.Markdown("**Submit**: Click the submit button to get the prediction from the model.")
189
 
190
  with gr.Accordion("User Preferences", open=False):