AashitaK commited on
Commit
69bea74
·
verified ·
1 Parent(s): b61d48e

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +32 -0
app.py ADDED
@@ -0,0 +1,32 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import anthropic
3
+ import os
4
+
5
+ # Load Anthropic API key from environment variables
6
+ api_key = os.getenv("ANTHROPIC_API_KEY")
7
+ client = anthropic.Anthropic(api_key=api_key)
8
+
9
+ def chatbot(prompt):
10
+ try:
11
+ response = client.messages.create(
12
+ model="claude-3-opus-20240229",
13
+ max_tokens=1024,
14
+ messages=[
15
+ {"role": "user", "content": prompt}
16
+ ]
17
+ )
18
+ return response.content[0].text # Extract text response
19
+ except Exception as e:
20
+ return str(e)
21
+
22
+ # Create a Gradio interface
23
+ iface = gr.Interface(
24
+ fn=chatbot,
25
+ inputs="text",
26
+ outputs="text",
27
+ title="Claude AI Chatbot",
28
+ description="Ask me anything!"
29
+ )
30
+
31
+ if __name__ == "__main__":
32
+ iface.launch()