-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathapp.py
91 lines (77 loc) · 2.9 KB
/
app.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
import streamlit as st
import pandas as pd
import anthropic
import os
# Set up Anthropic API client
api_key = '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'
client = anthropic.Client(api_key=api_key)
# Set the page configuration
st.set_page_config(page_title='Fraud Detection System', page_icon=':shield:', layout='centered', initial_sidebar_state='expanded')
# Custom CSS for styling
st.markdown("""
<style>
.main-title {
font-size: 36px;
font-weight: bold;
color: black;
text-align: center;
margin-top: -50px;
}
.sidebar .sidebar-content {
background-color: #f0f2f6;
padding: 10px;
}
.stButton button {
background-color: #4CAF50;
color: white;
border-radius: 8px;
}
.stButton button:hover {
background-color: #45a049;
}
.stDataFrame {
background-color: #f7f9fc;
border-radius: 8px;
padding: 10px;
}
.footer {
font-size: 14px;
text-align: center;
color: #888888;
margin-top: 50px;
}
</style>
""", unsafe_allow_html=True)
# App Title
st.markdown('<h1 class="main-title">Real-Time Fraud Detection System Using Claude</h1>', unsafe_allow_html=True)
# Sidebar for uploading transaction data
st.sidebar.header('Upload Transaction Data')
uploaded_file = st.sidebar.file_uploader("Choose a CSV file", type=["csv"])
if uploaded_file is not None:
# Read the uploaded file
data = pd.read_csv(uploaded_file)
# Display the data in the app
st.subheader('Transaction Data')
st.dataframe(data)
# Prepare transaction data as a string for Claude
transaction_text = data.to_string(index=False)
# Placeholder for analysis
st.subheader('Analyzing for Anomalies...')
if st.button('Run Real-Time Analysis'):
# Send transaction data to Claude for analysis
prompt = f"\n\nHuman: Analyze the following transactions and identify any that may be fraudulent:\n{transaction_text}\n\nAssistant:"
# Use the completion method correctly
response = client.completions.create(
model="claude-v1", # Specify the correct model version
prompt=prompt,
max_tokens_to_sample=500
)
# Access the text from the response directly
predictions = response.completion
# Display the predictions from Claude
st.subheader('Fraud Detection Results')
st.write(predictions)
else:
st.write("Please upload transaction data to analyze.")
# Footer
st.sidebar.markdown('<div class="footer">Developed by [Your Name]</div>', unsafe_allow_html=True)