edsl 0.1.39__py3-none-any.whl → 0.1.39.dev1__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- edsl/Base.py +116 -197
- edsl/__init__.py +7 -15
- edsl/__version__.py +1 -1
- edsl/agents/Agent.py +147 -351
- edsl/agents/AgentList.py +73 -211
- edsl/agents/Invigilator.py +50 -101
- edsl/agents/InvigilatorBase.py +70 -62
- edsl/agents/PromptConstructor.py +225 -143
- edsl/agents/__init__.py +1 -0
- edsl/agents/prompt_helpers.py +3 -3
- edsl/auto/AutoStudy.py +5 -18
- edsl/auto/StageBase.py +40 -53
- edsl/auto/StageQuestions.py +1 -2
- edsl/auto/utilities.py +6 -0
- edsl/config.py +2 -22
- edsl/conversation/car_buying.py +1 -2
- edsl/coop/PriceFetcher.py +1 -1
- edsl/coop/coop.py +47 -125
- edsl/coop/utils.py +14 -14
- edsl/data/Cache.py +27 -45
- edsl/data/CacheEntry.py +15 -12
- edsl/data/CacheHandler.py +12 -31
- edsl/data/RemoteCacheSync.py +46 -154
- edsl/data/__init__.py +3 -4
- edsl/data_transfer_models.py +1 -2
- edsl/enums.py +0 -27
- edsl/exceptions/__init__.py +50 -50
- edsl/exceptions/agents.py +0 -12
- edsl/exceptions/questions.py +6 -24
- edsl/exceptions/scenarios.py +0 -7
- edsl/inference_services/AnthropicService.py +19 -38
- edsl/inference_services/AwsBedrock.py +2 -0
- edsl/inference_services/AzureAI.py +2 -0
- edsl/inference_services/GoogleService.py +12 -7
- edsl/inference_services/InferenceServiceABC.py +85 -18
- edsl/inference_services/InferenceServicesCollection.py +79 -120
- edsl/inference_services/MistralAIService.py +3 -0
- edsl/inference_services/OpenAIService.py +35 -47
- edsl/inference_services/PerplexityService.py +3 -0
- edsl/inference_services/TestService.py +10 -11
- edsl/inference_services/TogetherAIService.py +3 -5
- edsl/jobs/Answers.py +14 -1
- edsl/jobs/Jobs.py +431 -356
- edsl/jobs/JobsChecks.py +10 -35
- edsl/jobs/JobsPrompts.py +4 -6
- edsl/jobs/JobsRemoteInferenceHandler.py +133 -205
- edsl/jobs/buckets/BucketCollection.py +3 -44
- edsl/jobs/buckets/TokenBucket.py +21 -53
- edsl/jobs/interviews/Interview.py +408 -143
- edsl/jobs/runners/JobsRunnerAsyncio.py +403 -88
- edsl/jobs/runners/JobsRunnerStatus.py +165 -133
- edsl/jobs/tasks/QuestionTaskCreator.py +19 -21
- edsl/jobs/tasks/TaskHistory.py +18 -38
- edsl/jobs/tasks/task_status_enum.py +2 -0
- edsl/language_models/KeyLookup.py +30 -0
- edsl/language_models/LanguageModel.py +236 -194
- edsl/language_models/ModelList.py +19 -28
- edsl/language_models/__init__.py +2 -1
- edsl/language_models/registry.py +190 -0
- edsl/language_models/repair.py +2 -2
- edsl/language_models/unused/ReplicateBase.py +83 -0
- edsl/language_models/utilities.py +4 -5
- edsl/notebooks/Notebook.py +14 -19
- edsl/prompts/Prompt.py +39 -29
- edsl/questions/{answer_validator_mixin.py → AnswerValidatorMixin.py} +2 -47
- edsl/questions/QuestionBase.py +214 -68
- edsl/questions/{question_base_gen_mixin.py → QuestionBaseGenMixin.py} +50 -57
- edsl/questions/QuestionBasePromptsMixin.py +3 -7
- edsl/questions/QuestionBudget.py +1 -1
- edsl/questions/QuestionCheckBox.py +3 -3
- edsl/questions/QuestionExtract.py +7 -5
- edsl/questions/QuestionFreeText.py +3 -2
- edsl/questions/QuestionList.py +18 -10
- edsl/questions/QuestionMultipleChoice.py +23 -67
- edsl/questions/QuestionNumerical.py +4 -2
- edsl/questions/QuestionRank.py +17 -7
- edsl/questions/{response_validator_abc.py → ResponseValidatorABC.py} +26 -40
- edsl/questions/SimpleAskMixin.py +3 -4
- edsl/questions/__init__.py +1 -2
- edsl/questions/derived/QuestionLinearScale.py +3 -6
- edsl/questions/derived/QuestionTopK.py +1 -1
- edsl/questions/descriptors.py +3 -17
- edsl/questions/question_registry.py +1 -1
- edsl/results/CSSParameterizer.py +1 -1
- edsl/results/Dataset.py +7 -170
- edsl/results/DatasetExportMixin.py +305 -168
- edsl/results/DatasetTree.py +8 -28
- edsl/results/Result.py +206 -298
- edsl/results/Results.py +131 -149
- edsl/results/ResultsDBMixin.py +238 -0
- edsl/results/ResultsExportMixin.py +0 -2
- edsl/results/{results_selector.py → Selector.py} +13 -23
- edsl/results/TableDisplay.py +171 -98
- edsl/results/__init__.py +1 -1
- edsl/scenarios/FileStore.py +239 -150
- edsl/scenarios/Scenario.py +193 -90
- edsl/scenarios/ScenarioHtmlMixin.py +3 -4
- edsl/scenarios/{scenario_join.py → ScenarioJoin.py} +6 -10
- edsl/scenarios/ScenarioList.py +244 -415
- edsl/scenarios/ScenarioListExportMixin.py +7 -0
- edsl/scenarios/ScenarioListPdfMixin.py +37 -15
- edsl/scenarios/__init__.py +2 -1
- edsl/study/ObjectEntry.py +1 -1
- edsl/study/SnapShot.py +1 -1
- edsl/study/Study.py +12 -5
- edsl/surveys/Rule.py +4 -5
- edsl/surveys/RuleCollection.py +27 -25
- edsl/surveys/Survey.py +791 -270
- edsl/surveys/SurveyCSS.py +8 -20
- edsl/surveys/{SurveyFlowVisualization.py → SurveyFlowVisualizationMixin.py} +9 -11
- edsl/surveys/__init__.py +2 -4
- edsl/surveys/descriptors.py +2 -6
- edsl/surveys/instructions/ChangeInstruction.py +2 -1
- edsl/surveys/instructions/Instruction.py +13 -4
- edsl/surveys/instructions/InstructionCollection.py +6 -11
- edsl/templates/error_reporting/interview_details.html +1 -1
- edsl/templates/error_reporting/report.html +1 -1
- edsl/tools/plotting.py +1 -1
- edsl/utilities/utilities.py +23 -35
- {edsl-0.1.39.dist-info → edsl-0.1.39.dev1.dist-info}/METADATA +10 -12
- edsl-0.1.39.dev1.dist-info/RECORD +277 -0
- {edsl-0.1.39.dist-info → edsl-0.1.39.dev1.dist-info}/WHEEL +1 -1
- edsl/agents/QuestionInstructionPromptBuilder.py +0 -128
- edsl/agents/QuestionTemplateReplacementsBuilder.py +0 -137
- edsl/agents/question_option_processor.py +0 -172
- edsl/coop/CoopFunctionsMixin.py +0 -15
- edsl/coop/ExpectedParrotKeyHandler.py +0 -125
- edsl/exceptions/inference_services.py +0 -5
- edsl/inference_services/AvailableModelCacheHandler.py +0 -184
- edsl/inference_services/AvailableModelFetcher.py +0 -215
- edsl/inference_services/ServiceAvailability.py +0 -135
- edsl/inference_services/data_structures.py +0 -134
- edsl/jobs/AnswerQuestionFunctionConstructor.py +0 -223
- edsl/jobs/FetchInvigilator.py +0 -47
- edsl/jobs/InterviewTaskManager.py +0 -98
- edsl/jobs/InterviewsConstructor.py +0 -50
- edsl/jobs/JobsComponentConstructor.py +0 -189
- edsl/jobs/JobsRemoteInferenceLogger.py +0 -239
- edsl/jobs/RequestTokenEstimator.py +0 -30
- edsl/jobs/async_interview_runner.py +0 -138
- edsl/jobs/buckets/TokenBucketAPI.py +0 -211
- edsl/jobs/buckets/TokenBucketClient.py +0 -191
- edsl/jobs/check_survey_scenario_compatibility.py +0 -85
- edsl/jobs/data_structures.py +0 -120
- edsl/jobs/decorators.py +0 -35
- edsl/jobs/jobs_status_enums.py +0 -9
- edsl/jobs/loggers/HTMLTableJobLogger.py +0 -304
- edsl/jobs/results_exceptions_handler.py +0 -98
- edsl/language_models/ComputeCost.py +0 -63
- edsl/language_models/PriceManager.py +0 -127
- edsl/language_models/RawResponseHandler.py +0 -106
- edsl/language_models/ServiceDataSources.py +0 -0
- edsl/language_models/key_management/KeyLookup.py +0 -63
- edsl/language_models/key_management/KeyLookupBuilder.py +0 -273
- edsl/language_models/key_management/KeyLookupCollection.py +0 -38
- edsl/language_models/key_management/__init__.py +0 -0
- edsl/language_models/key_management/models.py +0 -131
- edsl/language_models/model.py +0 -256
- edsl/notebooks/NotebookToLaTeX.py +0 -142
- edsl/questions/ExceptionExplainer.py +0 -77
- edsl/questions/HTMLQuestion.py +0 -103
- edsl/questions/QuestionMatrix.py +0 -265
- edsl/questions/data_structures.py +0 -20
- edsl/questions/loop_processor.py +0 -149
- edsl/questions/response_validator_factory.py +0 -34
- edsl/questions/templates/matrix/__init__.py +0 -1
- edsl/questions/templates/matrix/answering_instructions.jinja +0 -5
- edsl/questions/templates/matrix/question_presentation.jinja +0 -20
- edsl/results/MarkdownToDocx.py +0 -122
- edsl/results/MarkdownToPDF.py +0 -111
- edsl/results/TextEditor.py +0 -50
- edsl/results/file_exports.py +0 -252
- edsl/results/smart_objects.py +0 -96
- edsl/results/table_data_class.py +0 -12
- edsl/results/table_renderers.py +0 -118
- edsl/scenarios/ConstructDownloadLink.py +0 -109
- edsl/scenarios/DocumentChunker.py +0 -102
- edsl/scenarios/DocxScenario.py +0 -16
- edsl/scenarios/PdfExtractor.py +0 -40
- edsl/scenarios/directory_scanner.py +0 -96
- edsl/scenarios/file_methods.py +0 -85
- edsl/scenarios/handlers/__init__.py +0 -13
- edsl/scenarios/handlers/csv.py +0 -49
- edsl/scenarios/handlers/docx.py +0 -76
- edsl/scenarios/handlers/html.py +0 -37
- edsl/scenarios/handlers/json.py +0 -111
- edsl/scenarios/handlers/latex.py +0 -5
- edsl/scenarios/handlers/md.py +0 -51
- edsl/scenarios/handlers/pdf.py +0 -68
- edsl/scenarios/handlers/png.py +0 -39
- edsl/scenarios/handlers/pptx.py +0 -105
- edsl/scenarios/handlers/py.py +0 -294
- edsl/scenarios/handlers/sql.py +0 -313
- edsl/scenarios/handlers/sqlite.py +0 -149
- edsl/scenarios/handlers/txt.py +0 -33
- edsl/scenarios/scenario_selector.py +0 -156
- edsl/surveys/ConstructDAG.py +0 -92
- edsl/surveys/EditSurvey.py +0 -221
- edsl/surveys/InstructionHandler.py +0 -100
- edsl/surveys/MemoryManagement.py +0 -72
- edsl/surveys/RuleManager.py +0 -172
- edsl/surveys/Simulator.py +0 -75
- edsl/surveys/SurveyToApp.py +0 -141
- edsl/utilities/PrettyList.py +0 -56
- edsl/utilities/is_notebook.py +0 -18
- edsl/utilities/is_valid_variable_name.py +0 -11
- edsl/utilities/remove_edsl_version.py +0 -24
- edsl-0.1.39.dist-info/RECORD +0 -358
- /edsl/questions/{register_questions_meta.py → RegisterQuestionsMeta.py} +0 -0
- /edsl/results/{results_fetch_mixin.py → ResultsFetchMixin.py} +0 -0
- /edsl/results/{results_tools_mixin.py → ResultsToolsMixin.py} +0 -0
- {edsl-0.1.39.dist-info → edsl-0.1.39.dev1.dist-info}/LICENSE +0 -0
edsl/scenarios/handlers/docx.py
DELETED
@@ -1,76 +0,0 @@
|
|
1
|
-
from edsl.scenarios.file_methods import FileMethods
|
2
|
-
import os
|
3
|
-
import tempfile
|
4
|
-
|
5
|
-
|
6
|
-
class DocxMethods(FileMethods):
|
7
|
-
suffix = "docx"
|
8
|
-
|
9
|
-
def extract_text(self):
|
10
|
-
from docx import Document
|
11
|
-
|
12
|
-
self.doc = Document(self.path)
|
13
|
-
|
14
|
-
# Extract all text
|
15
|
-
full_text = []
|
16
|
-
for para in self.doc.paragraphs:
|
17
|
-
full_text.append(para.text)
|
18
|
-
|
19
|
-
text = "\n".join(full_text)
|
20
|
-
return text
|
21
|
-
|
22
|
-
def view_system(self):
|
23
|
-
import os
|
24
|
-
import subprocess
|
25
|
-
|
26
|
-
if os.path.exists(self.path):
|
27
|
-
try:
|
28
|
-
if (os_name := os.name) == "posix":
|
29
|
-
subprocess.run(["open", self.path], check=True) # macOS
|
30
|
-
elif os_name == "nt":
|
31
|
-
os.startfile(self.path) # Windows
|
32
|
-
else:
|
33
|
-
subprocess.run(["xdg-open", self.path], check=True) # Linux
|
34
|
-
except Exception as e:
|
35
|
-
print(f"Error opening DOCX: {e}")
|
36
|
-
else:
|
37
|
-
print("DOCX file was not found.")
|
38
|
-
|
39
|
-
def view_notebook(self):
|
40
|
-
import mammoth
|
41
|
-
from IPython.display import HTML, display
|
42
|
-
|
43
|
-
with open(self.path, "rb") as docx_file:
|
44
|
-
result = mammoth.convert_to_html(docx_file)
|
45
|
-
html = f"""
|
46
|
-
<div style="width: 800px; height: 800px; padding: 20px;
|
47
|
-
border: 1px solid #ccc; overflow-y: auto;">
|
48
|
-
{result.value}
|
49
|
-
</div>
|
50
|
-
"""
|
51
|
-
display(HTML(html))
|
52
|
-
|
53
|
-
def example(self):
|
54
|
-
from docx import Document
|
55
|
-
from edsl.scenarios.Scenario import Scenario
|
56
|
-
from edsl.scenarios.ScenarioList import ScenarioList
|
57
|
-
|
58
|
-
os.makedirs("test_dir", exist_ok=True)
|
59
|
-
doc1 = Document()
|
60
|
-
_ = doc1.add_heading("First Survey")
|
61
|
-
doc1.save("test_dir/test1.docx")
|
62
|
-
doc2 = Document()
|
63
|
-
_ = doc2.add_heading("Second Survey")
|
64
|
-
|
65
|
-
with tempfile.NamedTemporaryFile(delete=False, suffix=".docx") as tmp:
|
66
|
-
doc2.save(tmp.name)
|
67
|
-
tmp.close()
|
68
|
-
|
69
|
-
return tmp.name
|
70
|
-
|
71
|
-
|
72
|
-
if __name__ == "__main__":
|
73
|
-
docx_temp = DocxMethods.example()
|
74
|
-
from edsl.scenarios.FileStore import FileStore
|
75
|
-
|
76
|
-
fs = FileStore(docx_temp)
|
edsl/scenarios/handlers/html.py
DELETED
@@ -1,37 +0,0 @@
|
|
1
|
-
from edsl.scenarios.file_methods import FileMethods
|
2
|
-
import tempfile
|
3
|
-
|
4
|
-
|
5
|
-
class HtmlMethods(FileMethods):
|
6
|
-
suffix = "html"
|
7
|
-
|
8
|
-
def view_system(self):
|
9
|
-
import webbrowser
|
10
|
-
|
11
|
-
# with open(self.path, "r") as f:
|
12
|
-
# html_string = f.read()
|
13
|
-
|
14
|
-
# html_path = self.to_tempfile()
|
15
|
-
# webbrowser.open("file://" + html_path)
|
16
|
-
webbrowser.open("file://" + self.path)
|
17
|
-
|
18
|
-
def view_notebook(self):
|
19
|
-
from IPython.display import IFrame, display
|
20
|
-
|
21
|
-
display(IFrame(self.path, width=800, height=800))
|
22
|
-
|
23
|
-
def example(self):
|
24
|
-
html_string = b"""
|
25
|
-
<html>
|
26
|
-
<head>
|
27
|
-
<title>Test</title>
|
28
|
-
</head>
|
29
|
-
<body>
|
30
|
-
<h1>Hello, World!</h1>
|
31
|
-
</body>
|
32
|
-
</html>
|
33
|
-
"""
|
34
|
-
|
35
|
-
with tempfile.NamedTemporaryFile(delete=False, suffix=".html") as f:
|
36
|
-
f.write(html_string)
|
37
|
-
return f.name
|
edsl/scenarios/handlers/json.py
DELETED
@@ -1,111 +0,0 @@
|
|
1
|
-
from edsl.scenarios.file_methods import FileMethods
|
2
|
-
import tempfile
|
3
|
-
import json
|
4
|
-
from typing import Optional, Dict, Any
|
5
|
-
|
6
|
-
|
7
|
-
class JsonMethods(FileMethods):
|
8
|
-
suffix = "json"
|
9
|
-
|
10
|
-
def view_system(self):
|
11
|
-
import os
|
12
|
-
import subprocess
|
13
|
-
|
14
|
-
if os.path.exists(self.path):
|
15
|
-
try:
|
16
|
-
if (os_name := os.name) == "posix":
|
17
|
-
subprocess.run(["open", self.path], check=True) # macOS
|
18
|
-
elif os_name == "nt":
|
19
|
-
os.startfile(self.path) # Windows
|
20
|
-
else:
|
21
|
-
subprocess.run(["xdg-open", self.path], check=True) # Linux
|
22
|
-
except Exception as e:
|
23
|
-
print(f"Error opening JSON: {e}")
|
24
|
-
else:
|
25
|
-
print("JSON file was not found.")
|
26
|
-
|
27
|
-
def view_notebook(self):
|
28
|
-
from IPython.display import FileLink, JSON, display
|
29
|
-
import json
|
30
|
-
|
31
|
-
# Read and parse the JSON file
|
32
|
-
try:
|
33
|
-
with open(self.path, "r", encoding="utf-8") as f:
|
34
|
-
content = json.load(f)
|
35
|
-
|
36
|
-
# Display formatted JSON
|
37
|
-
display(JSON(content))
|
38
|
-
|
39
|
-
# Provide download link
|
40
|
-
display(FileLink(self.path))
|
41
|
-
except json.JSONDecodeError as e:
|
42
|
-
print(f"Error parsing JSON: {e}")
|
43
|
-
except Exception as e:
|
44
|
-
print(f"Error reading file: {e}")
|
45
|
-
|
46
|
-
def validate_json(self, schema: Optional[Dict[str, Any]] = None) -> bool:
|
47
|
-
"""
|
48
|
-
Validate the JSON file against a schema if provided,
|
49
|
-
or check if it's valid JSON if no schema is provided.
|
50
|
-
"""
|
51
|
-
try:
|
52
|
-
with open(self.path, "r", encoding="utf-8") as f:
|
53
|
-
content = json.load(f)
|
54
|
-
|
55
|
-
if schema is not None:
|
56
|
-
from jsonschema import validate
|
57
|
-
|
58
|
-
validate(instance=content, schema=schema)
|
59
|
-
|
60
|
-
return True
|
61
|
-
except json.JSONDecodeError as e:
|
62
|
-
print(f"Invalid JSON format: {e}")
|
63
|
-
return False
|
64
|
-
except Exception as e:
|
65
|
-
print(f"Validation error: {e}")
|
66
|
-
return False
|
67
|
-
|
68
|
-
def pretty_print(self):
|
69
|
-
"""Pretty print the JSON content with proper indentation."""
|
70
|
-
try:
|
71
|
-
with open(self.path, "r", encoding="utf-8") as f:
|
72
|
-
content = json.load(f)
|
73
|
-
|
74
|
-
pretty_json = json.dumps(content, indent=2, sort_keys=True)
|
75
|
-
print(pretty_json)
|
76
|
-
except Exception as e:
|
77
|
-
print(f"Error pretty printing JSON: {e}")
|
78
|
-
|
79
|
-
def example(self):
|
80
|
-
sample_json = {
|
81
|
-
"person": {
|
82
|
-
"name": "John Doe",
|
83
|
-
"age": 30,
|
84
|
-
"contact": {"email": "john@example.com", "phone": "+1-555-555-5555"},
|
85
|
-
"interests": ["programming", "data science", "machine learning"],
|
86
|
-
"active": True,
|
87
|
-
"metadata": {"last_updated": "2024-01-01", "version": 1.0},
|
88
|
-
}
|
89
|
-
}
|
90
|
-
|
91
|
-
with tempfile.NamedTemporaryFile(
|
92
|
-
delete=False, suffix=".json", mode="w", encoding="utf-8"
|
93
|
-
) as f:
|
94
|
-
json.dump(sample_json, f, indent=2)
|
95
|
-
return f.name
|
96
|
-
|
97
|
-
def format_file(self):
|
98
|
-
"""Read, format, and write back the JSON with consistent formatting."""
|
99
|
-
try:
|
100
|
-
# Read the current content
|
101
|
-
with open(self.path, "r", encoding="utf-8") as f:
|
102
|
-
content = json.load(f)
|
103
|
-
|
104
|
-
# Write back with consistent formatting
|
105
|
-
with open(self.path, "w", encoding="utf-8") as f:
|
106
|
-
json.dump(content, f, indent=2, sort_keys=True)
|
107
|
-
|
108
|
-
return True
|
109
|
-
except Exception as e:
|
110
|
-
print(f"Error formatting JSON file: {e}")
|
111
|
-
return False
|
edsl/scenarios/handlers/latex.py
DELETED
edsl/scenarios/handlers/md.py
DELETED
@@ -1,51 +0,0 @@
|
|
1
|
-
from edsl.scenarios.file_methods import FileMethods
|
2
|
-
import tempfile
|
3
|
-
|
4
|
-
|
5
|
-
class MarkdownMethods(FileMethods):
|
6
|
-
suffix = "md"
|
7
|
-
|
8
|
-
def view_system(self):
|
9
|
-
import os
|
10
|
-
import subprocess
|
11
|
-
|
12
|
-
if os.path.exists(self.path):
|
13
|
-
try:
|
14
|
-
if (os_name := os.name) == "posix":
|
15
|
-
subprocess.run(["open", self.path], check=True) # macOS
|
16
|
-
elif os_name == "nt":
|
17
|
-
os.startfile(self.path) # Windows
|
18
|
-
else:
|
19
|
-
subprocess.run(["xdg-open", self.path], check=True) # Linux
|
20
|
-
except Exception as e:
|
21
|
-
print(f"Error opening Markdown: {e}")
|
22
|
-
else:
|
23
|
-
print("Markdown file was not found.")
|
24
|
-
|
25
|
-
def view_notebook(self):
|
26
|
-
from IPython.display import FileLink, Markdown, display
|
27
|
-
|
28
|
-
# First display the content of the markdown file
|
29
|
-
with open(self.path, "r", encoding="utf-8") as f:
|
30
|
-
content = f.read()
|
31
|
-
display(Markdown(content))
|
32
|
-
|
33
|
-
# Then provide a download link
|
34
|
-
display(FileLink(self.path))
|
35
|
-
|
36
|
-
def example(self):
|
37
|
-
markdown_content = """# Sample Markdown
|
38
|
-
|
39
|
-
## Features
|
40
|
-
- **Bold text** demonstration
|
41
|
-
- *Italic text* demonstration
|
42
|
-
- Code block example:
|
43
|
-
```python
|
44
|
-
print("Hello, World!")
|
45
|
-
```
|
46
|
-
"""
|
47
|
-
with tempfile.NamedTemporaryFile(
|
48
|
-
delete=False, suffix=".md", mode="w", encoding="utf-8"
|
49
|
-
) as f:
|
50
|
-
f.write(markdown_content)
|
51
|
-
return f.name
|
edsl/scenarios/handlers/pdf.py
DELETED
@@ -1,68 +0,0 @@
|
|
1
|
-
import os
|
2
|
-
import base64
|
3
|
-
|
4
|
-
from edsl.scenarios.file_methods import FileMethods
|
5
|
-
|
6
|
-
|
7
|
-
class PdfMethods(FileMethods):
|
8
|
-
suffix = "pdf"
|
9
|
-
|
10
|
-
def extract_text(self):
|
11
|
-
from PyPDF2 import PdfReader
|
12
|
-
|
13
|
-
# Create a PDF reader object
|
14
|
-
reader = PdfReader(self.path)
|
15
|
-
|
16
|
-
# Get number of pages
|
17
|
-
num_pages = len(reader.pages)
|
18
|
-
|
19
|
-
# Extract text from all pages
|
20
|
-
text = ""
|
21
|
-
for page_num in range(num_pages):
|
22
|
-
# Get the page object
|
23
|
-
page = reader.pages[page_num]
|
24
|
-
# Extract text from page
|
25
|
-
text += page.extract_text()
|
26
|
-
|
27
|
-
return text
|
28
|
-
|
29
|
-
def view_system(self):
|
30
|
-
import os
|
31
|
-
import subprocess
|
32
|
-
|
33
|
-
if os.path.exists(self.path):
|
34
|
-
try:
|
35
|
-
if (os_name := os.name) == "posix":
|
36
|
-
subprocess.run(["open", self.path], check=True) # macOS
|
37
|
-
elif os_name == "nt":
|
38
|
-
os.startfile(self.path) # Windows
|
39
|
-
else:
|
40
|
-
subprocess.run(["xdg-open", self.path], check=True) # Linux
|
41
|
-
except Exception as e:
|
42
|
-
print(f"Error opening PDF: {e}")
|
43
|
-
else:
|
44
|
-
print("PDF file was not found.")
|
45
|
-
|
46
|
-
def view_notebook(self):
|
47
|
-
from IPython.display import HTML, display
|
48
|
-
|
49
|
-
with open(self.path, "rb") as f:
|
50
|
-
base64_pdf = base64.b64encode(f.read()).decode("utf-8")
|
51
|
-
|
52
|
-
html = f"""
|
53
|
-
<iframe
|
54
|
-
src="data:application/pdf;base64,{base64_pdf}"
|
55
|
-
width="800px"
|
56
|
-
height="800px"
|
57
|
-
type="application/pdf"
|
58
|
-
></iframe>
|
59
|
-
"""
|
60
|
-
display(HTML(html))
|
61
|
-
return
|
62
|
-
|
63
|
-
def example(self):
|
64
|
-
from edsl.results.Results import Results
|
65
|
-
|
66
|
-
return (
|
67
|
-
Results.example().select("answer.how_feeling").first().pdf().to_tempfile()
|
68
|
-
)
|
edsl/scenarios/handlers/png.py
DELETED
@@ -1,39 +0,0 @@
|
|
1
|
-
import tempfile
|
2
|
-
from edsl.scenarios.file_methods import FileMethods
|
3
|
-
|
4
|
-
|
5
|
-
class PngMethods(FileMethods):
|
6
|
-
suffix = "png"
|
7
|
-
|
8
|
-
def view_system(self):
|
9
|
-
import os
|
10
|
-
import subprocess
|
11
|
-
|
12
|
-
if os.path.exists(self.path):
|
13
|
-
try:
|
14
|
-
if (os_name := os.name) == "posix":
|
15
|
-
subprocess.run(["open", self.path], check=True) # macOS
|
16
|
-
elif os_name == "nt":
|
17
|
-
os.startfile(self.path) # Windows
|
18
|
-
else:
|
19
|
-
subprocess.run(["xdg-open", self.path], check=True) # Linux
|
20
|
-
except Exception as e:
|
21
|
-
print(f"Error opening PNG: {e}")
|
22
|
-
else:
|
23
|
-
print("PNG file was not found.")
|
24
|
-
|
25
|
-
def view_notebook(self):
|
26
|
-
from IPython.display import Image, display
|
27
|
-
|
28
|
-
display(Image(filename=self.path))
|
29
|
-
|
30
|
-
def example(self):
|
31
|
-
import matplotlib.pyplot as plt
|
32
|
-
import numpy as np
|
33
|
-
|
34
|
-
x = np.linspace(0, 10, 100)
|
35
|
-
y = np.sin(x)
|
36
|
-
plt.plot(x, y)
|
37
|
-
with tempfile.NamedTemporaryFile(delete=False, suffix=".png") as f:
|
38
|
-
plt.savefig(f.name)
|
39
|
-
return f.name
|
edsl/scenarios/handlers/pptx.py
DELETED
@@ -1,105 +0,0 @@
|
|
1
|
-
from edsl.scenarios.file_methods import FileMethods
|
2
|
-
import os
|
3
|
-
import tempfile
|
4
|
-
|
5
|
-
|
6
|
-
class PptxMethods(FileMethods):
|
7
|
-
suffix = "pptx"
|
8
|
-
|
9
|
-
def extract_text(self):
|
10
|
-
from pptx import Presentation
|
11
|
-
|
12
|
-
self.ppt = Presentation(self.path)
|
13
|
-
|
14
|
-
# Extract all text from slides
|
15
|
-
full_text = []
|
16
|
-
for slide in self.ppt.slides:
|
17
|
-
slide_text = []
|
18
|
-
for shape in slide.shapes:
|
19
|
-
if hasattr(shape, "text"):
|
20
|
-
slide_text.append(shape.text)
|
21
|
-
full_text.append("\n".join(slide_text))
|
22
|
-
|
23
|
-
text = "\n\n".join(full_text)
|
24
|
-
return text
|
25
|
-
|
26
|
-
def view_system(self):
|
27
|
-
import os
|
28
|
-
import subprocess
|
29
|
-
|
30
|
-
if os.path.exists(self.path):
|
31
|
-
try:
|
32
|
-
if (os_name := os.name) == "posix":
|
33
|
-
subprocess.run(["open", self.path], check=True) # macOS
|
34
|
-
elif os_name == "nt":
|
35
|
-
os.startfile(self.path) # Windows
|
36
|
-
else:
|
37
|
-
subprocess.run(["xdg-open", self.path], check=True) # Linux
|
38
|
-
except Exception as e:
|
39
|
-
print(f"Error opening PPTX: {e}")
|
40
|
-
else:
|
41
|
-
print("PPTX file was not found.")
|
42
|
-
|
43
|
-
def view_notebook(self):
|
44
|
-
from pptx import Presentation
|
45
|
-
from IPython.display import HTML, display
|
46
|
-
|
47
|
-
prs = Presentation(self.path)
|
48
|
-
|
49
|
-
# Create a simple HTML representation of the slides
|
50
|
-
html_content = []
|
51
|
-
for i, slide in enumerate(prs.slides, 1):
|
52
|
-
slide_content = []
|
53
|
-
for shape in slide.shapes:
|
54
|
-
if hasattr(shape, "text"):
|
55
|
-
slide_content.append(f"<p>{shape.text}</p>")
|
56
|
-
|
57
|
-
html_content.append(
|
58
|
-
f"""
|
59
|
-
<div style='border: 1px solid #ccc; margin: 10px; padding: 10px;'>
|
60
|
-
<h3>Slide {i}</h3>
|
61
|
-
{''.join(slide_content)}
|
62
|
-
</div>
|
63
|
-
"""
|
64
|
-
)
|
65
|
-
|
66
|
-
html = f"""
|
67
|
-
<div style="width: 800px; height: 800px; padding: 20px;
|
68
|
-
border: 1px solid #ccc; overflow-y: auto;">
|
69
|
-
{''.join(html_content)}
|
70
|
-
</div>
|
71
|
-
"""
|
72
|
-
display(HTML(html))
|
73
|
-
|
74
|
-
def example(self):
|
75
|
-
from pptx import Presentation
|
76
|
-
from edsl.scenarios.Scenario import Scenario
|
77
|
-
from edsl.scenarios.ScenarioList import ScenarioList
|
78
|
-
|
79
|
-
os.makedirs("test_dir", exist_ok=True)
|
80
|
-
|
81
|
-
# Create first presentation
|
82
|
-
ppt1 = Presentation()
|
83
|
-
slide = ppt1.slides.add_slide(ppt1.slide_layouts[0])
|
84
|
-
title = slide.shapes.title
|
85
|
-
title.text = "First Presentation"
|
86
|
-
ppt1.save("test_dir/test1.pptx")
|
87
|
-
|
88
|
-
# Create second presentation
|
89
|
-
ppt2 = Presentation()
|
90
|
-
slide = ppt2.slides.add_slide(ppt2.slide_layouts[0])
|
91
|
-
title = slide.shapes.title
|
92
|
-
title.text = "Second Presentation"
|
93
|
-
|
94
|
-
with tempfile.NamedTemporaryFile(delete=False, suffix=".pptx") as tmp:
|
95
|
-
ppt2.save(tmp.name)
|
96
|
-
tmp.close()
|
97
|
-
|
98
|
-
return tmp.name
|
99
|
-
|
100
|
-
|
101
|
-
if __name__ == "__main__":
|
102
|
-
pptx_temp = PptxMethods.example()
|
103
|
-
from edsl.scenarios.FileStore import FileStore
|
104
|
-
|
105
|
-
fs = FileStore(pptx_temp)
|