import streamlit as st import os import requests # Define Hugging Face API details API_URL = "https://api-inference.huggingface.co/models/Huzaifa367/chat-summarizer" API_TOKEN = os.getenv("AUTH_TOKEN") HEADERS = {"Authorization": f"Bearer {API_TOKEN}"} # Function to query Hugging Face API def query_huggingface(payload): try: response = requests.post(API_URL, headers=HEADERS, json=payload) response.raise_for_status() # Raise exception for non-2xx status codes return response.json() except requests.exceptions.RequestException as e: st.error(f"Error querying Hugging Face API: {e}") return {"summary_text": f"Error querying Hugging Face API: {e}"} def main(): st.set_page_config(layout="centered") st.title("Chat Summarizer") # User input for chat message user_message = st.text_input("User Message", "Enter your message here...") # Process user input and query Hugging Face API if st.button("Summarize"): if user_message: # Construct input text for summarization (no system message) input_text = f"User: {user_message}" # Query Hugging Face API for summarization payload = {"inputs": input_text} response = query_huggingface(payload) # Extract summary text from the API response summary_text = response[0]["summary_text"] if isinstance(response, list) else response.get("summary_text", "") # Display summary text st.text_area("Summary", value=summary_text) with st.sidebar: if st.button("Chat With PDF"): st.switch_page('app.py') if __name__ == "__main__": main()