Huzaifa367 commited on
Commit
7e4be94
·
verified ·
1 Parent(s): fa83c09

Update pages/summarizer.py

Browse files
Files changed (1) hide show
  1. 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("User Message", "Enter your message here...")
28
 
29
- # Process user input and query Hugging Face API
30
- if st.button("Summarize"):
31
  if user_message:
32
- # Construct input text for summarization (no system message)
 
 
 
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[0]["summary_text"] if isinstance(response, list) else response.get("summary_text", "")
41
 
42
- # Display summary text
43
- st.text_area("Summary", value=summary_text)
44
 
45
- with st.sidebar:
46
- if st.button("Chat With PDF"):
47
- st.switch_page('app.py')
 
 
 
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()