Vaishu16 commited on
Commit
9e160b4
Β·
verified Β·
1 Parent(s): 67cac15

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +35 -41
app.py CHANGED
@@ -30,9 +30,15 @@ suggested_questions = [
30
  "What was the revenue growth of"
31
  ]
32
 
33
- # Streamlit UI
34
- st.title("Question Completion Model")
35
- st.write("Enter a partial question related to financial statements, corporate governance, or company reports, and the app will intelligently complete it based on learned patterns!")
 
 
 
 
 
 
36
 
37
  # Session state for input question
38
  if "partial_question" not in st.session_state:
@@ -43,49 +49,37 @@ def update_input(selected_question):
43
  st.session_state.partial_question = selected_question
44
  st.rerun()
45
 
46
- # Display suggested partial questions
47
- st.write("### Suggested Partial Questions:")
48
- cols = st.columns(5)
49
  for i, question in enumerate(suggested_questions):
50
- if cols[i % 5].button(question, key=f"suggested_{i}"): # Place buttons in columns
51
  update_input(question)
52
 
53
  # Text input box
 
54
  partial_question = st.text_input("Enter a partial question:", st.session_state.partial_question)
55
 
56
- # Button to generate 3 completed questions
57
- if st.button("Complete Question"):
58
  if partial_question.strip():
59
- outputs = question_completion_pipeline(
60
- partial_question,
61
- max_length=60,
62
- num_return_sequences=3, # Generate 3 different completions
63
- do_sample=True,
64
- truncation=True
65
- )
66
-
67
- st.write("### Completed Questions:")
68
- for output in outputs:
69
- completed_question = output["generated_text"]
70
- st.markdown(f"**{completed_question}**") # Display non-clickable text
71
-
 
 
 
 
 
 
72
  else:
73
- st.warning("Please enter a partial question.")
74
-
75
-
76
-
77
-
78
-
79
-
80
-
81
-
82
-
83
-
84
-
85
-
86
-
87
-
88
-
89
-
90
-
91
-
 
30
  "What was the revenue growth of"
31
  ]
32
 
33
+ # Sidebar Settings
34
+ st.sidebar.header("πŸ”§ Settings")
35
+ max_length = st.sidebar.slider("Max Length", 30, 100, 60, step=5)
36
+ num_return_sequences = st.sidebar.slider("Number of Completions", 1, 5, 3)
37
+ sampling = st.sidebar.checkbox("Enable Sampling", value=True)
38
+
39
+ # Main UI
40
+ st.title("πŸ€– Question Completion Model")
41
+ st.write("Enter a partial question related to **financial statements, corporate governance, or company reports**, and the model will intelligently complete it!")
42
 
43
  # Session state for input question
44
  if "partial_question" not in st.session_state:
 
49
  st.session_state.partial_question = selected_question
50
  st.rerun()
51
 
52
+ # Display suggested partial questions in sidebar
53
+ st.sidebar.subheader("πŸ’‘ Suggested Partial Questions")
 
54
  for i, question in enumerate(suggested_questions):
55
+ if st.sidebar.button(question, key=f"suggested_{i}"):
56
  update_input(question)
57
 
58
  # Text input box
59
+ st.subheader("✏️ Enter Partial Question")
60
  partial_question = st.text_input("Enter a partial question:", st.session_state.partial_question)
61
 
62
+ # Generate button
63
+ if st.button("πŸš€ Complete Question"):
64
  if partial_question.strip():
65
+ with st.spinner("⏳ Generating completed questions... Please wait!"):
66
+ outputs = question_completion_pipeline(
67
+ partial_question,
68
+ max_length=max_length,
69
+ num_return_sequences=num_return_sequences,
70
+ do_sample=sampling,
71
+ truncation=True
72
+ )
73
+
74
+ st.subheader("βœ… Completed Questions")
75
+ completed_texts = [output["generated_text"] for output in outputs]
76
+
77
+ # Display completed questions inside an expander
78
+ with st.expander("πŸ” View Generated Questions"):
79
+ for idx, completed_question in enumerate(completed_texts):
80
+ st.markdown(f"**{idx+1}. {completed_question}**")
81
+
82
+ # Copy option
83
+ st.text_area("πŸ“‹ Copy Completed Questions:", "\n".join(completed_texts), height=150)
84
  else:
85
+ st.warning("⚠️ Please enter a partial question.")