Spaces:
Sleeping
Sleeping
Upload 2 files
Browse files- requirements.txt +2 -2
- simple_casl_app.py +44 -48
requirements.txt
CHANGED
@@ -2,8 +2,8 @@ gradio>=4.0.0
|
|
2 |
pandas>=1.3.0
|
3 |
numpy>=1.20.0
|
4 |
matplotlib>=3.3.0
|
5 |
-
|
6 |
reportlab>=3.6.0
|
7 |
PyPDF2>=2.0.0
|
8 |
-
|
9 |
pydub>=0.25.0
|
|
|
2 |
pandas>=1.3.0
|
3 |
numpy>=1.20.0
|
4 |
matplotlib>=3.3.0
|
5 |
+
requests>=2.25.0
|
6 |
reportlab>=3.6.0
|
7 |
PyPDF2>=2.0.0
|
8 |
+
speech_recognition>=3.8.0
|
9 |
pydub>=0.25.0
|
simple_casl_app.py
CHANGED
@@ -1,70 +1,62 @@
|
|
1 |
import gradio as gr
|
2 |
-
import boto3
|
3 |
import json
|
4 |
import os
|
5 |
import logging
|
|
|
6 |
|
7 |
# Configure logging
|
8 |
logging.basicConfig(level=logging.INFO)
|
9 |
logger = logging.getLogger(__name__)
|
10 |
|
11 |
-
#
|
12 |
-
|
13 |
-
AWS_SECRET_KEY = os.getenv("AWS_SECRET_KEY", "")
|
14 |
-
AWS_REGION = os.getenv("AWS_REGION", "us-east-1")
|
15 |
|
16 |
-
#
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
'bedrock-runtime',
|
22 |
-
aws_access_key_id=AWS_ACCESS_KEY,
|
23 |
-
aws_secret_access_key=AWS_SECRET_KEY,
|
24 |
-
region_name=AWS_REGION
|
25 |
-
)
|
26 |
-
logger.info("Bedrock client initialized successfully")
|
27 |
-
except Exception as e:
|
28 |
-
logger.error(f"Failed to initialize AWS Bedrock client: {str(e)}")
|
29 |
|
30 |
-
def
|
31 |
-
"""Call
|
32 |
-
if not
|
33 |
-
return "β
|
34 |
|
35 |
try:
|
36 |
-
|
37 |
-
"
|
|
|
|
|
|
|
|
|
|
|
|
|
38 |
"max_tokens": 4096,
|
39 |
-
"top_k": 250,
|
40 |
-
"stop_sequences": [],
|
41 |
-
"temperature": 0.3,
|
42 |
-
"top_p": 0.9,
|
43 |
"messages": [
|
44 |
{
|
45 |
"role": "user",
|
46 |
-
"content":
|
47 |
-
{
|
48 |
-
"type": "text",
|
49 |
-
"text": prompt
|
50 |
-
}
|
51 |
-
]
|
52 |
}
|
53 |
]
|
54 |
-
}
|
55 |
|
56 |
-
response =
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
)
|
62 |
-
response_body = json.loads(response.get('body').read())
|
63 |
-
return response_body['content'][0]['text']
|
64 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
65 |
except Exception as e:
|
66 |
-
logger.error(f"Error calling
|
67 |
-
return f"β Error
|
68 |
|
69 |
def process_file(file):
|
70 |
"""Process uploaded file"""
|
@@ -125,8 +117,8 @@ def analyze_transcript(file, age, gender):
|
|
125 |
Provide realistic standard scores (70-130 range, mean=100).
|
126 |
"""
|
127 |
|
128 |
-
# Get analysis from
|
129 |
-
result =
|
130 |
return result
|
131 |
|
132 |
# Create simple interface
|
@@ -181,7 +173,11 @@ with gr.Blocks(title="Simple CASL Analysis", theme=gr.themes.Soft()) as app:
|
|
181 |
|
182 |
if __name__ == "__main__":
|
183 |
print("π Starting Simple CASL Analysis Tool...")
|
184 |
-
if not
|
185 |
-
print("β οΈ
|
|
|
|
|
|
|
|
|
186 |
|
187 |
app.launch(show_api=False)
|
|
|
1 |
import gradio as gr
|
|
|
2 |
import json
|
3 |
import os
|
4 |
import logging
|
5 |
+
import requests
|
6 |
|
7 |
# Configure logging
|
8 |
logging.basicConfig(level=logging.INFO)
|
9 |
logger = logging.getLogger(__name__)
|
10 |
|
11 |
+
# Anthropic API key - can be set as HuggingFace secret or environment variable
|
12 |
+
ANTHROPIC_API_KEY = os.getenv("ANTHROPIC_API_KEY", "")
|
|
|
|
|
13 |
|
14 |
+
# Check if API key is available
|
15 |
+
if ANTHROPIC_API_KEY:
|
16 |
+
logger.info("Claude API key found")
|
17 |
+
else:
|
18 |
+
logger.warning("Claude API key not found - using demo mode")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
19 |
|
20 |
+
def call_claude_api(prompt):
|
21 |
+
"""Call Claude API directly"""
|
22 |
+
if not ANTHROPIC_API_KEY:
|
23 |
+
return "β Claude API key not configured. Please set ANTHROPIC_API_KEY environment variable."
|
24 |
|
25 |
try:
|
26 |
+
headers = {
|
27 |
+
"Content-Type": "application/json",
|
28 |
+
"x-api-key": ANTHROPIC_API_KEY,
|
29 |
+
"anthropic-version": "2023-06-01"
|
30 |
+
}
|
31 |
+
|
32 |
+
data = {
|
33 |
+
"model": "claude-3-5-sonnet-20241022",
|
34 |
"max_tokens": 4096,
|
|
|
|
|
|
|
|
|
35 |
"messages": [
|
36 |
{
|
37 |
"role": "user",
|
38 |
+
"content": prompt
|
|
|
|
|
|
|
|
|
|
|
39 |
}
|
40 |
]
|
41 |
+
}
|
42 |
|
43 |
+
response = requests.post(
|
44 |
+
"https://api.anthropic.com/v1/messages",
|
45 |
+
headers=headers,
|
46 |
+
json=data,
|
47 |
+
timeout=60
|
48 |
)
|
|
|
|
|
49 |
|
50 |
+
if response.status_code == 200:
|
51 |
+
response_json = response.json()
|
52 |
+
return response_json['content'][0]['text']
|
53 |
+
else:
|
54 |
+
logger.error(f"Claude API error: {response.status_code} - {response.text}")
|
55 |
+
return f"β Claude API Error: {response.status_code}"
|
56 |
+
|
57 |
except Exception as e:
|
58 |
+
logger.error(f"Error calling Claude API: {str(e)}")
|
59 |
+
return f"β Error: {str(e)}"
|
60 |
|
61 |
def process_file(file):
|
62 |
"""Process uploaded file"""
|
|
|
117 |
Provide realistic standard scores (70-130 range, mean=100).
|
118 |
"""
|
119 |
|
120 |
+
# Get analysis from Claude API
|
121 |
+
result = call_claude_api(prompt)
|
122 |
return result
|
123 |
|
124 |
# Create simple interface
|
|
|
173 |
|
174 |
if __name__ == "__main__":
|
175 |
print("π Starting Simple CASL Analysis Tool...")
|
176 |
+
if not ANTHROPIC_API_KEY:
|
177 |
+
print("β οΈ ANTHROPIC_API_KEY not configured - analysis will show error message")
|
178 |
+
print(" For HuggingFace Spaces: Add ANTHROPIC_API_KEY as a secret in your space settings")
|
179 |
+
print(" For local use: export ANTHROPIC_API_KEY='your-key-here'")
|
180 |
+
else:
|
181 |
+
print("β
Claude API configured")
|
182 |
|
183 |
app.launch(show_api=False)
|