Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -113,18 +113,9 @@ if "documents" in st.session_state:
|
|
| 113 |
"Identify research gaps",
|
| 114 |
"Suggest research ideas",
|
| 115 |
"Simulate a debate",
|
| 116 |
-
"Translate response",
|
| 117 |
"Generate citation"
|
| 118 |
])
|
| 119 |
|
| 120 |
-
# Translation language input with option to add custom
|
| 121 |
-
default_languages = ["Spanish", "French", "German", "Chinese", "Urdu", "Other"]
|
| 122 |
-
selected_language = st.selectbox("π Choose translation language (only for Translate task):", default_languages)
|
| 123 |
-
if selected_language == "Other":
|
| 124 |
-
user_language = st.text_input("Please enter your desired language:", key="custom_lang")
|
| 125 |
-
else:
|
| 126 |
-
user_language = selected_language
|
| 127 |
-
|
| 128 |
if st.button("π Run Agent"):
|
| 129 |
with st.spinner("Running agents..."):
|
| 130 |
docs = st.session_state.documents[:10]
|
|
@@ -170,17 +161,6 @@ if "documents" in st.session_state:
|
|
| 170 |
st.markdown("### π Debate")
|
| 171 |
st.write(debate)
|
| 172 |
|
| 173 |
-
# Translate agent
|
| 174 |
-
elif task == "Translate response":
|
| 175 |
-
if "last_agent_output" in st.session_state:
|
| 176 |
-
to_translate = st.session_state["last_agent_output"]
|
| 177 |
-
translate_chain = LLMChain(llm=llm, prompt=translate_prompt)
|
| 178 |
-
translated = translate_chain.invoke({"language": user_language, "content": to_translate})
|
| 179 |
-
st.markdown(f"### π Translated Response ({user_language})")
|
| 180 |
-
st.write(translated)
|
| 181 |
-
else:
|
| 182 |
-
st.warning("Please run another agent first (e.g., Summary, Gap, Debate) to generate something to translate.")
|
| 183 |
-
|
| 184 |
# Citation agent
|
| 185 |
elif task == "Generate citation":
|
| 186 |
citation_chain = create_stuff_documents_chain(llm, citation_prompt)
|
|
@@ -188,3 +168,24 @@ if "documents" in st.session_state:
|
|
| 188 |
st.session_state["last_agent_output"] = citation
|
| 189 |
st.markdown("### π APA Citation")
|
| 190 |
st.code(citation, language="markdown")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 113 |
"Identify research gaps",
|
| 114 |
"Suggest research ideas",
|
| 115 |
"Simulate a debate",
|
|
|
|
| 116 |
"Generate citation"
|
| 117 |
])
|
| 118 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 119 |
if st.button("π Run Agent"):
|
| 120 |
with st.spinner("Running agents..."):
|
| 121 |
docs = st.session_state.documents[:10]
|
|
|
|
| 161 |
st.markdown("### π Debate")
|
| 162 |
st.write(debate)
|
| 163 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 164 |
# Citation agent
|
| 165 |
elif task == "Generate citation":
|
| 166 |
citation_chain = create_stuff_documents_chain(llm, citation_prompt)
|
|
|
|
| 168 |
st.session_state["last_agent_output"] = citation
|
| 169 |
st.markdown("### π APA Citation")
|
| 170 |
st.code(citation, language="markdown")
|
| 171 |
+
|
| 172 |
+
# Translation toggle after agent response
|
| 173 |
+
if "last_agent_output" in st.session_state:
|
| 174 |
+
if st.toggle("π Translate the response?"):
|
| 175 |
+
default_languages = ["Spanish", "French", "German", "Chinese", "Urdu", "Other"]
|
| 176 |
+
selected_language = st.selectbox("Choose translation language:", default_languages)
|
| 177 |
+
if selected_language == "Other":
|
| 178 |
+
user_language = st.text_input("Please enter your desired language:", key="custom_lang")
|
| 179 |
+
else:
|
| 180 |
+
user_language = selected_language
|
| 181 |
+
|
| 182 |
+
to_translate = st.session_state["last_agent_output"]
|
| 183 |
+
if isinstance(to_translate, dict):
|
| 184 |
+
combined_text = "\n\n".join(str(value) for value in to_translate.values())
|
| 185 |
+
else:
|
| 186 |
+
combined_text = str(to_translate)
|
| 187 |
+
|
| 188 |
+
translate_chain = LLMChain(llm=llm, prompt=translate_prompt)
|
| 189 |
+
translated = translate_chain.invoke({"language": user_language, "content": combined_text})
|
| 190 |
+
st.markdown(f"### π Translated Response ({user_language})")
|
| 191 |
+
st.write(translated)
|