Spaces:
Sleeping
Sleeping
| import gradio as gr | |
| import anthropic | |
| import os | |
| # Load Anthropic API key from environment variables | |
| api_key = os.getenv("ANTHROPIC_API_KEY") | |
| client = anthropic.Anthropic(api_key=api_key) | |
| def chatbot(prompt): | |
| try: | |
| response = client.messages.create( | |
| model="claude-3-opus-20240229", | |
| max_tokens=1024, | |
| messages=[ | |
| {"role": "user", "content": prompt} | |
| ] | |
| ) | |
| return response.content[0].text # Extract text response | |
| except Exception as e: | |
| return str(e) | |
| # Create a Gradio interface | |
| iface = gr.Interface( | |
| fn=chatbot, | |
| inputs="text", | |
| outputs="text", | |
| title="Claude AI Chatbot", | |
| description="Ask me anything!" | |
| ) | |
| if __name__ == "__main__": | |
| iface.launch() |