Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -13,8 +13,7 @@ def generate_more_factors(problem_statement, user_factors):
|
|
13 |
f"set of factors responsible for solving the problem. Provide your suggestions as a bullet list."
|
14 |
)
|
15 |
|
16 |
-
# 2. Call Hugging Face inference API
|
17 |
-
# Replace 'gpt2' with another model if needed.
|
18 |
API_URL = "https://api-inference.huggingface.co/models/gpt2"
|
19 |
token = st.secrets.get("HF_API_TOKEN", "")
|
20 |
headers = {"Authorization": f"Bearer {token}"} if token else {}
|
@@ -23,8 +22,8 @@ def generate_more_factors(problem_statement, user_factors):
|
|
23 |
if response.status_code == 200:
|
24 |
result = response.json()
|
25 |
if isinstance(result, list) and result and "generated_text" in result[0]:
|
26 |
-
# Remove the prompt from the generated output if it is repeated.
|
27 |
generated = result[0]["generated_text"]
|
|
|
28 |
suggestions = generated[len(prompt):].strip()
|
29 |
return suggestions
|
30 |
else:
|
@@ -34,39 +33,57 @@ def generate_more_factors(problem_statement, user_factors):
|
|
34 |
|
35 |
def main():
|
36 |
st.title("Problem Statement and Factor Guess")
|
37 |
-
st.write("
|
38 |
|
39 |
-
#
|
40 |
-
problem_statement = st.text_input("1. Enter your problem statement:")
|
41 |
-
|
42 |
-
st.write("2. Enter your factors (each factor in a separate textbox):")
|
43 |
-
|
44 |
-
# 2. Dynamic factor inputs stored in session_state
|
45 |
if "factor_rows" not in st.session_state:
|
46 |
st.session_state.factor_rows = [""]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
47 |
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
st.session_state.factor_rows[i] = value
|
55 |
|
56 |
-
# 3
|
57 |
-
|
58 |
-
st.
|
59 |
-
st.
|
|
|
|
|
|
|
|
|
|
|
|
|
60 |
|
61 |
-
# 4
|
62 |
-
|
63 |
-
|
64 |
-
|
|
|
65 |
else:
|
66 |
-
|
67 |
-
suggestions = generate_more_factors(problem_statement, factor_inputs)
|
68 |
-
st.markdown("### Generated Factors")
|
69 |
-
st.write(suggestions)
|
70 |
|
71 |
if __name__ == "__main__":
|
72 |
main()
|
|
|
13 |
f"set of factors responsible for solving the problem. Provide your suggestions as a bullet list."
|
14 |
)
|
15 |
|
16 |
+
# 2. Call Hugging Face inference API (using a sample model; replace as needed)
|
|
|
17 |
API_URL = "https://api-inference.huggingface.co/models/gpt2"
|
18 |
token = st.secrets.get("HF_API_TOKEN", "")
|
19 |
headers = {"Authorization": f"Bearer {token}"} if token else {}
|
|
|
22 |
if response.status_code == 200:
|
23 |
result = response.json()
|
24 |
if isinstance(result, list) and result and "generated_text" in result[0]:
|
|
|
25 |
generated = result[0]["generated_text"]
|
26 |
+
# Remove the prompt from the generated output
|
27 |
suggestions = generated[len(prompt):].strip()
|
28 |
return suggestions
|
29 |
else:
|
|
|
33 |
|
34 |
def main():
|
35 |
st.title("Problem Statement and Factor Guess")
|
36 |
+
st.write("Enter your problem statement and factors. The UI is organized into four horizontal levels:")
|
37 |
|
38 |
+
# Initialize session state variables
|
|
|
|
|
|
|
|
|
|
|
39 |
if "factor_rows" not in st.session_state:
|
40 |
st.session_state.factor_rows = [""]
|
41 |
+
if "llm_suggestions" not in st.session_state:
|
42 |
+
st.session_state.llm_suggestions = None
|
43 |
+
|
44 |
+
# Create four columns for the four levels
|
45 |
+
col1, col2, col3, col4 = st.columns(4)
|
46 |
+
|
47 |
+
# Level 1: Problem Statement (Left-most column)
|
48 |
+
with col1:
|
49 |
+
st.header("Level 1: Problem Statement")
|
50 |
+
problem_statement = st.text_input("Enter your problem statement:")
|
51 |
+
|
52 |
+
# Level 2: User-Provided Factors
|
53 |
+
with col2:
|
54 |
+
st.header("Level 2: Your Factors")
|
55 |
+
factor_inputs = []
|
56 |
+
for i in range(len(st.session_state.factor_rows)):
|
57 |
+
key = f"factor_{i}"
|
58 |
+
value = st.text_input(f"Factor {i+1}", value=st.session_state.factor_rows[i], key=key)
|
59 |
+
factor_inputs.append(value)
|
60 |
+
st.session_state.factor_rows[i] = value
|
61 |
|
62 |
+
if st.button("Add Factor Row", key="add_row"):
|
63 |
+
st.session_state.factor_rows.append("")
|
64 |
+
try:
|
65 |
+
st.experimental_rerun()
|
66 |
+
except AttributeError:
|
67 |
+
st.write("Row added. Please refresh the page to see the new row.")
|
|
|
68 |
|
69 |
+
# Level 3: Generate More Factors Button
|
70 |
+
with col3:
|
71 |
+
st.header("Level 3: Generate More Factors")
|
72 |
+
if st.button("Generate More Factors", key="generate_factors"):
|
73 |
+
if not problem_statement.strip():
|
74 |
+
st.error("Please enter a problem statement before generating factors.")
|
75 |
+
else:
|
76 |
+
with st.spinner("Generating more factors..."):
|
77 |
+
suggestions = generate_more_factors(problem_statement, factor_inputs)
|
78 |
+
st.session_state.llm_suggestions = suggestions
|
79 |
|
80 |
+
# Level 4: LLM Suggestions Display
|
81 |
+
with col4:
|
82 |
+
st.header("Level 4: LLM Suggestions")
|
83 |
+
if st.session_state.llm_suggestions:
|
84 |
+
st.write(st.session_state.llm_suggestions)
|
85 |
else:
|
86 |
+
st.write("LLM suggestions will appear here after you click 'Generate More Factors'.")
|
|
|
|
|
|
|
87 |
|
88 |
if __name__ == "__main__":
|
89 |
main()
|