DrishtiSharma commited on
Commit
e4ad6f0
·
verified ·
1 Parent(s): feae486

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +49 -46
app.py CHANGED
@@ -89,51 +89,54 @@ def generate_response(topic, length):
89
 
90
  return app.invoke(input={"topic": topic, "length": length})
91
 
92
- # Display chat messages from the session
93
- if "messages" in st.session_state:
94
- for message in st.session_state["messages"]:
95
- with st.chat_message(message["role"]):
96
- st.markdown(message["content"], unsafe_allow_html=True)
97
-
98
- # Handle user input
99
- if topic := st.chat_input(placeholder="📝 Ask a question or provide an essay topic...", disabled=st.session_state["chat_active"]):
100
- st.chat_message("user").markdown(topic)
101
- st.session_state["messages"].append({"role": "user", "content": topic})
102
-
103
- with st.spinner(" Generating your essay..."):
104
- response = generate_response(topic, essay_length)
105
-
106
- # Handle the assistant's response
107
- with st.chat_message("assistant"):
108
- if "essay" in response: # Display essay preview and download link
109
- st.markdown(f"### 📝 Essay Preview ({essay_length} words)")
110
- st.markdown(f"#### {response['essay']['header']}")
111
- st.markdown(response["essay"]["entry"])
112
- for para in response["essay"]["paragraphs"]:
113
- st.markdown(f"**{para['sub_header']}**")
114
- st.markdown(para["paragraph"])
115
- st.markdown("**🖊️ Conclusion:**")
116
- st.markdown(response["essay"]["conclusion"])
117
-
118
- # Provide download link for the PDF
119
- with open(response["pdf_name"], "rb") as pdf_file:
120
- b64 = base64.b64encode(pdf_file.read()).decode()
121
- href = f"<a href='data:application/octet-stream;base64,{b64}' download='{response['pdf_name']}'>📄 Click here to download the PDF</a>"
122
- st.markdown(href, unsafe_allow_html=True)
123
-
124
- # Save the assistant's message to session state
125
- st.session_state["messages"].append(
126
- {"role": "assistant", "content": f"Here is your {essay_length}-word essay preview and the download link."}
127
- )
128
- else: # For other responses (e.g., general answers)
129
- st.markdown(response["response"])
130
- st.session_state["messages"].append({"role": "assistant", "content": response["response"]})
131
-
132
-
133
- ----------
134
-
135
-
136
-
 
 
 
137
  with tab2:
138
  st.subheader("📊 Multi-Agent Workflow Visualization")
139
 
@@ -160,4 +163,4 @@ st.markdown(
160
  </div>
161
  """,
162
  unsafe_allow_html=True,
163
- )
 
89
 
90
  return app.invoke(input={"topic": topic, "length": length})
91
 
92
+ # Define Tabs
93
+ tab1, tab2 = st.tabs(["📜 Essay Generation", "📊 Workflow Visualization"])
94
+
95
+ # 📜 Tab 1: Essay Generation
96
+ with tab1:
97
+ st.subheader("📝 Generate an Essay")
98
+
99
+ # Display chat messages from the session
100
+ if "messages" in st.session_state:
101
+ for message in st.session_state["messages"]:
102
+ with st.chat_message(message["role"]):
103
+ st.markdown(message["content"], unsafe_allow_html=True)
104
+
105
+ # Handle user input
106
+ if topic := st.chat_input(placeholder="📝 Ask a question or provide an essay topic...", disabled=st.session_state["chat_active"]):
107
+ st.chat_message("user").markdown(topic)
108
+ st.session_state["messages"].append({"role": "user", "content": topic})
109
+
110
+ with st.spinner(" Generating your essay..."):
111
+ response = generate_response(topic, essay_length)
112
+
113
+ # Handle the assistant's response
114
+ with st.chat_message("assistant"):
115
+ if "essay" in response: # Display essay preview and download link
116
+ st.markdown(f"### 📝 Essay Preview ({essay_length} words)")
117
+ st.markdown(f"#### {response['essay']['header']}")
118
+ st.markdown(response["essay"]["entry"])
119
+ for para in response["essay"]["paragraphs"]:
120
+ st.markdown(f"**{para['sub_header']}**")
121
+ st.markdown(para["paragraph"])
122
+ st.markdown("**🖊️ Conclusion:**")
123
+ st.markdown(response["essay"]["conclusion"])
124
+
125
+ # Provide download link for the PDF
126
+ with open(response["pdf_name"], "rb") as pdf_file:
127
+ b64 = base64.b64encode(pdf_file.read()).decode()
128
+ href = f"<a href='data:application/octet-stream;base64,{b64}' download='{response['pdf_name']}'>📄 Click here to download the PDF</a>"
129
+ st.markdown(href, unsafe_allow_html=True)
130
+
131
+ # Save the assistant's message to session state
132
+ st.session_state["messages"].append(
133
+ {"role": "assistant", "content": f"Here is your {essay_length}-word essay preview and the download link."}
134
+ )
135
+ else: # For other responses (e.g., general answers)
136
+ st.markdown(response["response"])
137
+ st.session_state["messages"].append({"role": "assistant", "content": response["response"]})
138
+
139
+ # 📊 Tab 2: Workflow Visualization
140
  with tab2:
141
  st.subheader("📊 Multi-Agent Workflow Visualization")
142
 
 
163
  </div>
164
  """,
165
  unsafe_allow_html=True,
166
+ )