jhansi1 commited on
Commit
3ce6f8c
·
verified ·
1 Parent(s): 4597972

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +8 -3
app.py CHANGED
@@ -4,21 +4,26 @@ from transformers import pipeline
4
  # Load the fill-mask pipeline with the specified model
5
  @st.cache_resource
6
  def load_pipeline():
 
7
  pipe = pipeline("fill-mask", model="InfAI/parlbert-german-law")
8
  return pipe
9
 
 
10
  pipe = load_pipeline()
11
 
12
  # Streamlit app UI
13
  st.title("ParlBERT German Law Fill-in-the-Blank Assistant")
14
  st.write("Enter a sentence with a `[MASK]` token, and the model will predict possible words.")
15
 
16
- # Input text area for the sentence
17
  user_input = st.text_input("Your sentence (use [MASK] as a placeholder):", "Das Gesetz [MASK] den Bürger.")
18
 
19
- # Generate predictions
20
  if st.button("Generate Prediction"):
 
21
  predictions = pipe(user_input)
 
 
22
  st.write("Predicted Fill-ins:")
23
  for i, pred in enumerate(predictions):
24
- st.write(f"{i+1}. {pred['sequence']} (Score: {pred['score']:.4f})")
 
4
  # Load the fill-mask pipeline with the specified model
5
  @st.cache_resource
6
  def load_pipeline():
7
+ """Load the ParlBERT model for the fill-mask task."""
8
  pipe = pipeline("fill-mask", model="InfAI/parlbert-german-law")
9
  return pipe
10
 
11
+ # Load the pipeline
12
  pipe = load_pipeline()
13
 
14
  # Streamlit app UI
15
  st.title("ParlBERT German Law Fill-in-the-Blank Assistant")
16
  st.write("Enter a sentence with a `[MASK]` token, and the model will predict possible words.")
17
 
18
+ # Input text area for the sentence with a default example
19
  user_input = st.text_input("Your sentence (use [MASK] as a placeholder):", "Das Gesetz [MASK] den Bürger.")
20
 
21
+ # Generate predictions when the button is clicked
22
  if st.button("Generate Prediction"):
23
+ # Run the model on the input sentence
24
  predictions = pipe(user_input)
25
+
26
+ # Display predictions
27
  st.write("Predicted Fill-ins:")
28
  for i, pred in enumerate(predictions):
29
+ st.write(f"{i+1}. {pred['sequence']} (Score: {pred['score']:.4f})")