Spaces:
Sleeping
Sleeping
formix
commited on
Commit
·
12377a0
0
Parent(s):
init
Browse files- .gitignore +65 -0
- app.py +67 -0
.gitignore
ADDED
@@ -0,0 +1,65 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
__pycache__/
|
2 |
+
*.py[cod]
|
3 |
+
*.so
|
4 |
+
*.egg
|
5 |
+
*.egg-info
|
6 |
+
.eggs
|
7 |
+
dist/
|
8 |
+
build/
|
9 |
+
wheels/
|
10 |
+
pip-wheel-metadata/
|
11 |
+
*.manifest
|
12 |
+
*.spec
|
13 |
+
*.log
|
14 |
+
*.pot
|
15 |
+
*.pyc
|
16 |
+
*.pyo
|
17 |
+
*.pyd
|
18 |
+
*.sqlite3
|
19 |
+
*.sqlite
|
20 |
+
*.db
|
21 |
+
*.db-journal
|
22 |
+
*.csv
|
23 |
+
*.tsv
|
24 |
+
*.xlsx
|
25 |
+
*.xls
|
26 |
+
*.ipynb
|
27 |
+
.ipynb_checkpoints
|
28 |
+
htmlcov/
|
29 |
+
.tox/
|
30 |
+
.coverage
|
31 |
+
.coverage.*
|
32 |
+
.cache
|
33 |
+
nosetests.xml
|
34 |
+
coverage.xml
|
35 |
+
*.cover
|
36 |
+
*.py,cover
|
37 |
+
.hypothesis/
|
38 |
+
.pytest_cache/
|
39 |
+
cover/
|
40 |
+
*.orig
|
41 |
+
.scoverage/
|
42 |
+
*.class
|
43 |
+
*.gradle
|
44 |
+
.gradle/
|
45 |
+
build/
|
46 |
+
target/
|
47 |
+
tmp/
|
48 |
+
out/
|
49 |
+
release/
|
50 |
+
.idea/
|
51 |
+
.vscode/
|
52 |
+
__MACOSX/
|
53 |
+
*.iml
|
54 |
+
*.ipr
|
55 |
+
*.iws
|
56 |
+
*.bak
|
57 |
+
*.swp
|
58 |
+
*.swo
|
59 |
+
*.swn
|
60 |
+
.env
|
61 |
+
.env/
|
62 |
+
env/
|
63 |
+
venv/
|
64 |
+
venv/*
|
65 |
+
*.txt
|
app.py
ADDED
@@ -0,0 +1,67 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
import anthropic
|
3 |
+
from anthropic.types import ContentBlock
|
4 |
+
|
5 |
+
from time import time
|
6 |
+
client = anthropic.Anthropic()
|
7 |
+
|
8 |
+
# Read file content into a string
|
9 |
+
with open("full_text.txt", "r") as file:
|
10 |
+
text = file.read()
|
11 |
+
|
12 |
+
def claude_conversation(message, history):
|
13 |
+
# Prepare the conversation history
|
14 |
+
messages = []
|
15 |
+
for human, assistant in history:
|
16 |
+
if human.strip(): # Only add non-empty human messages
|
17 |
+
messages.append({"role": "user", "content": human})
|
18 |
+
if assistant.strip(): # Only add non-empty assistant messages
|
19 |
+
messages.append({"role": "assistant", "content": assistant})
|
20 |
+
|
21 |
+
# Add the new message if it's not empty
|
22 |
+
if message.strip():
|
23 |
+
messages.append({"role": "user", "content": message})
|
24 |
+
else:
|
25 |
+
return "Please enter a non-empty message."
|
26 |
+
|
27 |
+
try:
|
28 |
+
# Make the API call
|
29 |
+
|
30 |
+
start = time ()
|
31 |
+
response = client.beta.prompt_caching.messages.create(
|
32 |
+
model="claude-3-5-sonnet-20240620",
|
33 |
+
max_tokens=1024,
|
34 |
+
system=[
|
35 |
+
{
|
36 |
+
"type": "text",
|
37 |
+
"text": "You are an AI assistant tasked with analyzing legal documents."
|
38 |
+
},
|
39 |
+
{
|
40 |
+
"type": "text",
|
41 |
+
"text": text,
|
42 |
+
"cache_control": {"type": "ephemeral"}
|
43 |
+
}
|
44 |
+
],
|
45 |
+
messages=messages
|
46 |
+
)
|
47 |
+
|
48 |
+
# Extract and return Claude's response
|
49 |
+
|
50 |
+
print (response)
|
51 |
+
|
52 |
+
end = time ()
|
53 |
+
print(f"Elapsed time: {end - start} seconds")
|
54 |
+
|
55 |
+
return response.content[0].text
|
56 |
+
except anthropic.APIError as e:
|
57 |
+
return f"An error occurred: {str(e)}"
|
58 |
+
|
59 |
+
# Create the Gradio interface
|
60 |
+
demo = gr.ChatInterface(
|
61 |
+
fn=claude_conversation,
|
62 |
+
title="Claude Legal Document Analyzer",
|
63 |
+
description="Ask questions about the legal document loaded from 'mainarbeit.txt'."
|
64 |
+
)
|
65 |
+
|
66 |
+
# Launch the app
|
67 |
+
demo.launch()
|