Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
import anthropic
|
| 3 |
+
import os
|
| 4 |
+
from streamlit.components.v1 import html
|
| 5 |
+
|
| 6 |
+
# Set up the Anthropic client
|
| 7 |
+
client = anthropic.Anthropic(api_key=os.environ.get("ANTHROPIC_API_KEY"))
|
| 8 |
+
|
| 9 |
+
# Streamlit app
|
| 10 |
+
def main():
|
| 11 |
+
st.title("Claude 3.5 Sonnet API Demo")
|
| 12 |
+
|
| 13 |
+
# User input
|
| 14 |
+
user_input = st.text_area("Enter your message:", height=100)
|
| 15 |
+
|
| 16 |
+
if st.button("Send"):
|
| 17 |
+
if user_input:
|
| 18 |
+
# Call Claude API
|
| 19 |
+
response = client.messages.create(
|
| 20 |
+
model="claude-3-sonnet-20240229",
|
| 21 |
+
max_tokens=1000,
|
| 22 |
+
messages=[
|
| 23 |
+
{"role": "user", "content": user_input}
|
| 24 |
+
]
|
| 25 |
+
)
|
| 26 |
+
|
| 27 |
+
# Display Claude's response
|
| 28 |
+
st.write("Claude's response:")
|
| 29 |
+
st.write(response.content[0].text)
|
| 30 |
+
|
| 31 |
+
# Example of using a custom HTML/JS component
|
| 32 |
+
custom_html = """
|
| 33 |
+
<div id="custom-component">
|
| 34 |
+
<h3>Custom Component</h3>
|
| 35 |
+
<p>This is a custom HTML component.</p>
|
| 36 |
+
<button onclick="alert('Button clicked!')">Click me</button>
|
| 37 |
+
</div>
|
| 38 |
+
<script>
|
| 39 |
+
// You can add custom JavaScript here
|
| 40 |
+
console.log("Custom component loaded");
|
| 41 |
+
</script>
|
| 42 |
+
"""
|
| 43 |
+
html(custom_html, height=200)
|
| 44 |
+
|
| 45 |
+
if __name__ == "__main__":
|
| 46 |
+
main()
|