nnsohamnn commited on
Commit
043812c
·
verified ·
1 Parent(s): 952c5a9

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +40 -2
app.py CHANGED
@@ -140,6 +140,25 @@ def classify_interface(text):
140
  def generate_interface(prompt, length=50, temp=0.7):
141
  return generate_text(prompt, textgen_model, textgen_tokenizer, max_length=int(length), temperature=float(temp))
142
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
143
  # Create Gradio interface
144
  with gr.Blocks(title="Science Text Analyzer") as demo:
145
  gr.Markdown("# Science Text Analyzer")
@@ -156,6 +175,16 @@ with gr.Blocks(title="Science Text Analyzer") as demo:
156
  classify_button = gr.Button("Classify")
157
  with gr.Column():
158
  output = gr.Textbox(label="Classification Result", placeholder="The predicted subject and confidence will appear here.")
 
 
 
 
 
 
 
 
 
 
159
  classify_button.click(fn=classify_interface, inputs=text_input, outputs=output)
160
 
161
  with gr.Tab("Generate Text"):
@@ -172,6 +201,16 @@ with gr.Blocks(title="Science Text Analyzer") as demo:
172
  generate_button = gr.Button("Generate")
173
  with gr.Column():
174
  generated_output = gr.Textbox(label="Generated Text", lines=8, placeholder="The generated text will appear here.")
 
 
 
 
 
 
 
 
 
 
175
  generate_button.click(fn=generate_interface, inputs=[prompt_input, length_slider, temp_slider], outputs=generated_output)
176
 
177
  gr.Markdown("### About This App")
@@ -182,6 +221,5 @@ with gr.Blocks(title="Science Text Analyzer") as demo:
182
  "for **educational research**, **content creation**, and **curriculum support**."
183
  )
184
 
185
-
186
  # Launch the app
187
- demo.launch()
 
140
  def generate_interface(prompt, length=50, temp=0.7):
141
  return generate_text(prompt, textgen_model, textgen_tokenizer, max_length=int(length), temperature=float(temp))
142
 
143
+ # Define example inputs for the classifier
144
+ classifier_examples = [
145
+ ["The process of photosynthesis converts light energy into chemical energy, producing oxygen as a byproduct."],
146
+ ["The Pythagorean theorem states that in a right-angled triangle, the square of the length of the hypotenuse equals the sum of squares of the other two sides."],
147
+ ["The Industrial Revolution began in Great Britain in the late 18th century and spread to other parts of Europe and North America."],
148
+ ["Atoms consist of a nucleus containing protons and neutrons, surrounded by electrons that orbit in energy levels."],
149
+ ["Differential equations are mathematical equations that relate a function with its derivatives, representing rates of change."],
150
+ ["The Treaty of Versailles was signed in 1919, officially ending World War I and imposing harsh penalties on Germany."]
151
+ ]
152
+
153
+ # Define example inputs for the text generator
154
+ generator_examples = [
155
+ ["The structure of DNA consists of", 50, 0.7],
156
+ ["Newton's laws of motion explain", 75, 0.8],
157
+ ["Climate change affects ecosystems by", 100, 0.7],
158
+ ["Quantum mechanics revolutionized physics when", 60, 0.9],
159
+ ["Chemical reactions occur when", 50, 0.6]
160
+ ]
161
+
162
  # Create Gradio interface
163
  with gr.Blocks(title="Science Text Analyzer") as demo:
164
  gr.Markdown("# Science Text Analyzer")
 
175
  classify_button = gr.Button("Classify")
176
  with gr.Column():
177
  output = gr.Textbox(label="Classification Result", placeholder="The predicted subject and confidence will appear here.")
178
+
179
+ # Add examples for the classifier
180
+ gr.Examples(
181
+ examples=classifier_examples,
182
+ inputs=text_input,
183
+ outputs=output,
184
+ fn=classify_interface,
185
+ cache_examples=True
186
+ )
187
+
188
  classify_button.click(fn=classify_interface, inputs=text_input, outputs=output)
189
 
190
  with gr.Tab("Generate Text"):
 
201
  generate_button = gr.Button("Generate")
202
  with gr.Column():
203
  generated_output = gr.Textbox(label="Generated Text", lines=8, placeholder="The generated text will appear here.")
204
+
205
+ # Add examples for the text generator
206
+ gr.Examples(
207
+ examples=generator_examples,
208
+ inputs=[prompt_input, length_slider, temp_slider],
209
+ outputs=generated_output,
210
+ fn=generate_interface,
211
+ cache_examples=True
212
+ )
213
+
214
  generate_button.click(fn=generate_interface, inputs=[prompt_input, length_slider, temp_slider], outputs=generated_output)
215
 
216
  gr.Markdown("### About This App")
 
221
  "for **educational research**, **content creation**, and **curriculum support**."
222
  )
223
 
 
224
  # Launch the app
225
+ demo.launch()