Spaces:
Runtime error
Runtime error
Update pages/summarizer.py
Browse files- pages/summarizer.py +20 -13
pages/summarizer.py
CHANGED
@@ -17,19 +17,23 @@ def query_huggingface(payload):
|
|
17 |
st.error(f"Error querying Hugging Face API: {e}")
|
18 |
return {"summary_text": f"Error querying Hugging Face API: {e}"}
|
19 |
|
20 |
-
|
21 |
def main():
|
22 |
-
|
23 |
-
st.set_page_config(layout="centered")
|
24 |
st.title("Chat Summarizer")
|
25 |
|
|
|
|
|
|
|
26 |
# User input for chat message
|
27 |
-
user_message = st.text_input("
|
28 |
|
29 |
-
# Process user input and query Hugging Face API
|
30 |
-
if st.button("
|
31 |
if user_message:
|
32 |
-
#
|
|
|
|
|
|
|
33 |
input_text = f"User: {user_message}"
|
34 |
|
35 |
# Query Hugging Face API for summarization
|
@@ -37,14 +41,17 @@ def main():
|
|
37 |
response = query_huggingface(payload)
|
38 |
|
39 |
# Extract summary text from the API response
|
40 |
-
summary_text = response
|
41 |
|
42 |
-
#
|
43 |
-
|
44 |
|
45 |
-
|
46 |
-
|
47 |
-
|
|
|
|
|
|
|
48 |
|
49 |
if __name__ == "__main__":
|
50 |
main()
|
|
|
17 |
st.error(f"Error querying Hugging Face API: {e}")
|
18 |
return {"summary_text": f"Error querying Hugging Face API: {e}"}
|
19 |
|
|
|
20 |
def main():
|
21 |
+
st.set_page_config(layout="wide")
|
|
|
22 |
st.title("Chat Summarizer")
|
23 |
|
24 |
+
# Initialize a list to store chat messages
|
25 |
+
chat_history = []
|
26 |
+
|
27 |
# User input for chat message
|
28 |
+
user_message = st.text_input("Provide a Chat/Long description to summarize")
|
29 |
|
30 |
+
# Process user input and query Hugging Face API on button click
|
31 |
+
if st.button("Send"):
|
32 |
if user_message:
|
33 |
+
# Add user message to chat history
|
34 |
+
chat_history.append({"speaker": "User", "message": user_message})
|
35 |
+
|
36 |
+
# Construct input text for summarization
|
37 |
input_text = f"User: {user_message}"
|
38 |
|
39 |
# Query Hugging Face API for summarization
|
|
|
41 |
response = query_huggingface(payload)
|
42 |
|
43 |
# Extract summary text from the API response
|
44 |
+
summary_text = response.get("summary_text", "")
|
45 |
|
46 |
+
# Add summarization response to chat history
|
47 |
+
chat_history.append({"speaker": "Bot", "message": summary_text})
|
48 |
|
49 |
+
# Display chat history as a conversation
|
50 |
+
for chat in chat_history:
|
51 |
+
if chat["speaker"] == "User":
|
52 |
+
st.text_input("User", chat["message"], disabled=True)
|
53 |
+
elif chat["speaker"] == "Bot":
|
54 |
+
st.text_area("Bot", chat["message"], disabled=True)
|
55 |
|
56 |
if __name__ == "__main__":
|
57 |
main()
|