Spaces:
Configuration error
Configuration error
| import openai | |
| import os | |
| from dotenv import load_dotenv | |
| # Load environment variables | |
| load_dotenv() | |
| # Get API key from .env | |
| openai.api_key = os.getenv("OPENAI_API_KEY") | |
| def summarize_text(text): | |
| try: | |
| response = openai.ChatCompletion.create( | |
| model="gpt-3.5-turbo", # You can use gpt-4 if you have access | |
| messages=[ | |
| {"role": "system", "content": "You are a helpful assistant that summarizes content."}, | |
| {"role": "user", "content": f"Summarize the following text:\n\n{text}"} | |
| ], | |
| temperature=0.5, | |
| max_tokens=300 | |
| ) | |
| summary = response['choices'][0]['message']['content'].strip() | |
| return summary | |
| except Exception as e: | |
| return f"Error during summarization: {str(e)}" | |