dafajudin commited on
Commit
c56dd4d
Β·
1 Parent(s): 9464121

update code

Browse files
Files changed (2) hide show
  1. app.py +13 -61
  2. index.html +0 -1
app.py CHANGED
@@ -35,11 +35,11 @@ if USE_QLORA or USE_LORA:
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",
@@ -83,28 +83,6 @@ def format_answer(image, question, history):
83
  def clear_history():
84
  return None, "", [], ""
85
 
86
- def undo_last(history):
87
- if history:
88
- history.pop()
89
- if history:
90
- last_image, last_entry = history[-1]
91
- question = last_entry.split(" | ")[0].replace("Question: ", "")
92
- return last_image, question, last_entry, history
93
- return None, "", "", history
94
-
95
- def retry_last(history):
96
- if history:
97
- last_image, last_entry = history[-1]
98
- question = last_entry.split(" | ")[0].replace("Question: ", "")
99
- return format_answer(last_image, question, history[:-1])
100
- return None, "No previous analysis to retry.", history
101
-
102
- def switch_theme(mode):
103
- if mode == "Light Mode":
104
- return gr.themes.Default()
105
- else:
106
- return gr.themes.Soft(primary_hue=gr.themes.colors.green, secondary_hue=gr.themes.colors.green)
107
-
108
  def save_feedback(feedback):
109
  return "Thank you for your feedback!"
110
 
@@ -129,7 +107,9 @@ with gr.Blocks(
129
  image_input = gr.Image(label="Upload image", type="pil")
130
  with gr.Column():
131
  question_input = gr.Textbox(show_label=False, placeholder="Enter your question here...")
132
- submit_button = gr.Button("Submit", variant="primary")
 
 
133
  answer_output = gr.Textbox(label="Result Prediction")
134
 
135
  history_state = gr.State([]) # Initialize the history state
@@ -141,28 +121,11 @@ with gr.Blocks(
141
  show_progress=True
142
  )
143
 
144
- with gr.Row():
145
- retry_button = gr.Button("πŸ”„ Retry")
146
- undo_button = gr.Button("↩️ Undo")
147
- clear_button = gr.Button("πŸ—‘οΈ Clear")
148
-
149
- retry_button.click(
150
- retry_last,
151
- inputs=[history_state],
152
- outputs=[answer_output, image_input, question_input, history_state]
153
- )
154
-
155
- undo_button.click(
156
- undo_last,
157
- inputs=[history_state],
158
- outputs=[image_input, question_input, answer_output, history_state]
159
- )
160
-
161
- clear_button.click(
162
- clear_history,
163
- inputs=[],
164
- outputs=[image_input, question_input, answer_output, history_state]
165
- )
166
 
167
  with gr.Row():
168
  history_gallery = gr.Gallery(label="History Log", elem_id="history_log")
@@ -191,17 +154,6 @@ with gr.Blocks(
191
  gr.Markdown("**Enter your question**: Type the question you have about the image, such as 'What modality is used to take this image?'")
192
  gr.Markdown("**Submit**: Click the submit button to get the prediction from the model.")
193
 
194
- with gr.Accordion("User Preferences", open=False):
195
- gr.Markdown("**Mode**: Choose between light and dark mode for your comfort.")
196
- mode_selector = gr.Radio(choices=["Light Mode", "Dark Mode"], label="Select Mode")
197
- apply_theme_button = gr.Button("Apply Theme")
198
-
199
- apply_theme_button.click(
200
- switch_theme,
201
- inputs=[mode_selector],
202
- outputs=[],
203
- )
204
-
205
  with gr.Accordion("Feedback", open=False):
206
  gr.Markdown("**We value your feedback!** Please provide any feedback you have about this application.")
207
  feedback_input = gr.Textbox(label="Feedback", lines=4)
 
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",
 
83
  def clear_history():
84
  return None, "", [], ""
85
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
86
  def save_feedback(feedback):
87
  return "Thank you for your feedback!"
88
 
 
107
  image_input = gr.Image(label="Upload image", type="pil")
108
  with gr.Column():
109
  question_input = gr.Textbox(show_label=False, placeholder="Enter your question here...")
110
+ with gr.Row():
111
+ submit_button = gr.Button("Submit", variant="primary")
112
+ clear_button = gr.Button("πŸ—‘οΈ Clear")
113
  answer_output = gr.Textbox(label="Result Prediction")
114
 
115
  history_state = gr.State([]) # Initialize the history state
 
121
  show_progress=True
122
  )
123
 
124
+ clear_button.click(
125
+ clear_history,
126
+ inputs=[],
127
+ outputs=[image_input, question_input, answer_output, history_state]
128
+ )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
129
 
130
  with gr.Row():
131
  history_gallery = gr.Gallery(label="History Log", elem_id="history_log")
 
154
  gr.Markdown("**Enter your question**: Type the question you have about the image, such as 'What modality is used to take this image?'")
155
  gr.Markdown("**Submit**: Click the submit button to get the prediction from the model.")
156
 
 
 
 
 
 
 
 
 
 
 
 
157
  with gr.Accordion("Feedback", open=False):
158
  gr.Markdown("**We value your feedback!** Please provide any feedback you have about this application.")
159
  feedback_input = gr.Textbox(label="Feedback", lines=4)
index.html CHANGED
@@ -1,7 +1,6 @@
1
  <!DOCTYPE html>
2
  <html>
3
  <head>
4
- <link rel="stylesheet" href="file/style.css" />
5
  <link rel="preconnect" href="https://fonts.googleapis.com" />
6
  <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin />
7
  <link href="https://fonts.googleapis.com/css2?family=Source+Sans+Pro:wght@400;600;700&display=swap" rel="stylesheet" />
 
1
  <!DOCTYPE html>
2
  <html>
3
  <head>
 
4
  <link rel="preconnect" href="https://fonts.googleapis.com" />
5
  <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin />
6
  <link href="https://fonts.googleapis.com/css2?family=Source+Sans+Pro:wght@400;600;700&display=swap" rel="stylesheet" />