Mayada commited on
Commit
107fab0
1 Parent(s): 5b1faf1

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +17 -17
app.py CHANGED
@@ -85,32 +85,32 @@ def caption_question_interface(image):
85
  words = caption.split()
86
  # Generate questions for the first word
87
  if len(words) > 0:
88
- keyword = words[0]
89
- question = generate_questions(caption, keyword)
90
- questions_with_keywords.extend([(q, keyword) for q in question])
91
  # Generate questions for the second word
92
  if len(words) > 1:
93
- keyword = words[1]
94
- question = generate_questions(caption, keyword)
95
- questions_with_keywords.extend([(q, keyword) for q in question])
96
  # Generate questions for the second word + first word
97
  if len(words) > 1:
98
- keyword = " ".join(words[:2])
99
- question = generate_questions(caption, keyword)
100
- questions_with_keywords.extend([(q, keyword) for q in question])
101
  # Generate questions for the third word
102
  if len(words) > 2:
103
- keyword = words[2]
104
- question = generate_questions(caption, keyword)
105
- questions_with_keywords.extend([(q, keyword) for q in question])
106
  # Generate questions for the fourth word
107
  if len(words) > 3:
108
- keyword = words[3]
109
- question = generate_questions(caption, keyword)
110
- questions_with_answers.extend([(q, keyword) for q in question])
111
 
112
  # Format questions with answers
113
- formatted_questions = [f"Question: {q}\nKeyword: {a}" for q, a in questions_with_keywords]
114
  formatted_questions = "\n".join(formatted_questions)
115
 
116
  # Return the generated captions and formatted questions with answers
@@ -124,7 +124,7 @@ gr_interface = gr.Interface(
124
  gr.Textbox(label="Generated Questions")
125
  ],
126
  title="Visual Question Generator",
127
- description="Generate captions and questions for images using pre-trained models.",
128
  theme=seafoam,
129
  )
130
 
 
85
  words = caption.split()
86
  # Generate questions for the first word
87
  if len(words) > 0:
88
+ answer = words[0]
89
+ question = generate_questions(caption, answer)
90
+ questions_with_answers.extend([(q, answer) for q in question])
91
  # Generate questions for the second word
92
  if len(words) > 1:
93
+ answer = words[1]
94
+ question = generate_questions(caption, answer)
95
+ questions_with_answers.extend([(q, answer) for q in question])
96
  # Generate questions for the second word + first word
97
  if len(words) > 1:
98
+ answer = " ".join(words[:2])
99
+ question = generate_questions(caption, answer)
100
+ questions_with_answers.extend([(q, answer) for q in question])
101
  # Generate questions for the third word
102
  if len(words) > 2:
103
+ answer = words[2]
104
+ question = generate_questions(caption, answer)
105
+ questions_with_answers.extend([(q, answer) for q in question])
106
  # Generate questions for the fourth word
107
  if len(words) > 3:
108
+ answer = words[3]
109
+ question = generate_questions(caption, answer)
110
+ questions_with_answers.extend([(q, answer) for q in question])
111
 
112
  # Format questions with answers
113
+ formatted_questions = [f"Question: {q}\nKeyword: {a}" for q, a in questions_with_answers]
114
  formatted_questions = "\n".join(formatted_questions)
115
 
116
  # Return the generated captions and formatted questions with answers
 
124
  gr.Textbox(label="Generated Questions")
125
  ],
126
  title="Visual Question Generator",
127
+ description="Generate captions and questions for images using Arabic image captioning model and question generation model",
128
  theme=seafoam,
129
  )
130