Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
|
|
| 1 |
import streamlit as st
|
| 2 |
from transformers import pipeline, AutoModelForCausalLM, AutoTokenizer
|
| 3 |
|
|
@@ -20,24 +21,54 @@ question_completion_pipeline = pipeline(
|
|
| 20 |
device=-1
|
| 21 |
)
|
| 22 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 23 |
# Streamlit UI
|
| 24 |
st.title("Question Completion Model")
|
| 25 |
-
st.write("
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 26 |
|
| 27 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 28 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 29 |
if st.button("Complete Question"):
|
| 30 |
if partial_question.strip():
|
| 31 |
-
|
| 32 |
partial_question,
|
| 33 |
max_length=60,
|
| 34 |
-
num_return_sequences=
|
| 35 |
-
do_sample=True
|
|
|
|
| 36 |
)
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
|
|
|
|
|
|
| 41 |
else:
|
| 42 |
st.warning("Please enter a partial question.")
|
| 43 |
|
|
@@ -58,4 +89,3 @@ if st.button("Complete Question"):
|
|
| 58 |
|
| 59 |
|
| 60 |
|
| 61 |
-
|
|
|
|
| 1 |
+
|
| 2 |
import streamlit as st
|
| 3 |
from transformers import pipeline, AutoModelForCausalLM, AutoTokenizer
|
| 4 |
|
|
|
|
| 21 |
device=-1
|
| 22 |
)
|
| 23 |
|
| 24 |
+
# Suggested partial questions
|
| 25 |
+
suggested_questions = [
|
| 26 |
+
"What is the impact of",
|
| 27 |
+
"How does the company report",
|
| 28 |
+
"What are the financial risks of",
|
| 29 |
+
"Explain the corporate governance of",
|
| 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:
|
| 39 |
+
st.session_state.partial_question = ""
|
| 40 |
+
|
| 41 |
+
# Function to update input when a suggestion is clicked
|
| 42 |
+
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 |
|
|
|
|
| 89 |
|
| 90 |
|
| 91 |
|
|
|