Spaces:
Runtime error
Runtime error
Update pages/summarizer.py
Browse files1234562 unmodified lines9101112131415161718192021import streamlit as stimport osimport requests# Define Hugging Face API detailsAPI_URL = "https://api-inference.huggingface.co/models/Huzaifa367/chat-summarizer"2 unmodified lines# Function to query Hugging Face APIdef query_huggingface(payload):try:response = requests.post(API_URL, headers=HEADERS, json=payload)response.raise_for_status() # Raise exception for non-2xx status codesreturn 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="wide")123456782 unmodified lines111213141516171819202122232425262728293031323334353637import streamlit as stimport osimport requestsimport time# Define Hugging Face API detailsAPI_URL = "https://api-inference.huggingface.co/models/Huzaifa367/chat-summarizer"2 unmodified lines# Function to query Hugging Face APIdef query_huggingface(payload):max_retries=3retries = 0while retries < max_retries:try:response = requests.post(API_URL, headers=HEADERS, json=payload)response.raise_for_status() # Raise exception for non-2xx status codesreturn 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}"}except requests.exceptions.HTTPError as e:if response.status_code == 503:st.warning("Service temporarily unavailable. Retrying...")time.sleep(5) # Wait for a few seconds before retryingretries += 1else:st.error(f"HTTP Error querying Hugging Face API: {e.response.status_code}")return {"summary_text": "Service Unavailable. Please try again later."}except Exception as e:st.error(f"An unexpected error occurred: {e}")return {"summary_text": "An unexpected error occurred. Please try again later."}def main():st.set_page_config(layout="wide")
pages/summarizer.py+23-7