hosseinhimself commited on
Commit
92f7ad1
1 Parent(s): b299e67

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +20 -24
app.py CHANGED
@@ -44,11 +44,6 @@ chain = LLMChain(llm=llm_model, prompt=prompt)
44
 
45
  def evaluate(task_type, task_number, question, input_type, image=None, text=None):
46
  if input_type == "Image" and image is not None:
47
- # Ensure the image is in the correct format
48
- if isinstance(image, str):
49
- # Load the image if it's a URL or path
50
- image = Image.open(image)
51
-
52
  # Process the image to extract text
53
  text_content = ocr_pipe(image)
54
  content = text_content[0]['generated_text']
@@ -71,16 +66,7 @@ def evaluate(task_type, task_number, question, input_type, image=None, text=None
71
 
72
  return result
73
 
74
- # Create the Gradio interface
75
- inputs = [
76
- gr.Dropdown(choices=["Academic", "General"], label="Test Type", value="Academic"),
77
- gr.Dropdown(choices=["Task 1", "Task 2"], label="Task Number", value="Task 1"),
78
- gr.Textbox(label="Question", value=""),
79
- gr.Radio(choices=["Image", "Text"], label="Input Type", value="Image"),
80
- gr.Image(type="pil", label="Upload Image", visible=True),
81
- gr.Textbox(label="Enter Text", visible=False)
82
- ]
83
-
84
  def toggle_input(input_type):
85
  if input_type == "Image":
86
  return gr.update(visible=True), gr.update(visible=False)
@@ -114,18 +100,28 @@ footer_html_with_analytics = f"""
114
  </div>
115
  """
116
 
117
- outputs = gr.Markdown(label="Result")
118
-
119
- # Define the Gradio Blocks and Interface
120
  with gr.Blocks() as demo:
121
  gr.Markdown("# IELTS Writing Evaluation")
 
122
  with gr.Row():
123
- with gr.Column():
124
- input_type_radio = gr.Radio(choices=["Image", "Text"], label="Input Type", value="Image")
125
- image_input = gr.Image(type="pil", label="Upload Image", visible=True)
126
- text_input = gr.Textbox(label="Enter Text", visible=False)
127
- input_type_radio.change(toggle_input, input_type_radio, [image_input, text_input])
128
- gr.Interface(fn=evaluate, inputs=inputs, outputs=outputs)
 
 
 
 
 
 
 
 
 
 
 
129
  gr.HTML(footer_html_with_analytics)
130
 
131
  # Launch the interface
 
44
 
45
  def evaluate(task_type, task_number, question, input_type, image=None, text=None):
46
  if input_type == "Image" and image is not None:
 
 
 
 
 
47
  # Process the image to extract text
48
  text_content = ocr_pipe(image)
49
  content = text_content[0]['generated_text']
 
66
 
67
  return result
68
 
69
+ # Function to toggle the visibility of inputs based on the selected input type
 
 
 
 
 
 
 
 
 
70
  def toggle_input(input_type):
71
  if input_type == "Image":
72
  return gr.update(visible=True), gr.update(visible=False)
 
100
  </div>
101
  """
102
 
103
+ # Create the Gradio interface
 
 
104
  with gr.Blocks() as demo:
105
  gr.Markdown("# IELTS Writing Evaluation")
106
+
107
  with gr.Row():
108
+ test_type = gr.Dropdown(choices=["Academic", "General"], label="Test Type", value="Academic")
109
+ task_number = gr.Dropdown(choices=["Task 1", "Task 2"], label="Task Number", value="Task 1")
110
+ question = gr.Textbox(label="Question")
111
+ input_type = gr.Radio(choices=["Image", "Text"], label="Input Type", value="Image")
112
+
113
+ with gr.Row():
114
+ image_input = gr.Image(type="pil", label="Upload Image", visible=True)
115
+ text_input = gr.Textbox(label="Enter Text", visible=False)
116
+
117
+ input_type.change(toggle_input, [input_type], [image_input, text_input])
118
+
119
+ gr.Interface(
120
+ fn=evaluate,
121
+ inputs=[test_type, task_number, question, input_type, image_input, text_input],
122
+ outputs=gr.Markdown(label="Result")
123
+ )
124
+
125
  gr.HTML(footer_html_with_analytics)
126
 
127
  # Launch the interface