Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
|
@@ -35,7 +35,7 @@ TOTAL_SUMMARIZED_WORDS = 0
|
|
| 35 |
|
| 36 |
def generate_graph_snippet(placeholder_text: str, context: str, initial_query: str, crumbs: str) -> str:
|
| 37 |
prompt = f"""
|
| 38 |
-
Generate a full
|
| 39 |
{placeholder_text}
|
| 40 |
|
| 41 |
It will be integrated in a broader report (focus on the graph formatting though) about:
|
|
@@ -127,7 +127,7 @@ Keep in mind the:
|
|
| 127 |
{crumbs}
|
| 128 |
|
| 129 |
// Requirements
|
| 130 |
-
- use standard mermaid visual rendering (ex: flowchart, sequence, gantt, pie, mindmap
|
| 131 |
- no introduction, conclusions or code fences -> Output the result directly
|
| 132 |
- create only the content for the mermaid
|
| 133 |
- no comments of #color coding and classes inside the mermaid code generated, it's supposed to be only focused on the mermaid code required to render it
|
|
@@ -144,7 +144,7 @@ instead, use
|
|
| 144 |
G --> H[Performance Evaluation - 45% Speed Improvement, 35% Risk Profiling, 50% Fraud Detection]
|
| 145 |
- Similarly, do not use the symbol | in the mermaid code, it would create an error
|
| 146 |
- Do not use the gantt chart visual placeholder to generate a graph (ex: barchart), Gantt charts should only be used for timelines / project plans
|
| 147 |
-
Note: Visual placeholders are solely supposed to generate diagrams
|
| 148 |
- use only this type of quotation marks: ", others would lead to failure to render
|
| 149 |
- if you need to render a quotation mark inside the text of the diagram make sure to add escapechar so that mermaid interprets it correctly
|
| 150 |
- do not use commas in the content of each object / nodes, they will create rendering issues
|
|
@@ -153,14 +153,6 @@ Note: Visual placeholders are solely supposed to generate diagrams, for graphs,
|
|
| 153 |
// Examples
|
| 154 |
Note: Pay attention for each example to what type of parenthesis / bracket is used and respect it scrupulously
|
| 155 |
|
| 156 |
-
-- xy chart --
|
| 157 |
-
xychart-beta
|
| 158 |
-
title "Sales Revenue"
|
| 159 |
-
x-axis [jan, feb, mar, apr, may, jun, jul, aug, sep, oct, nov, dec]
|
| 160 |
-
y-axis "Revenue (in $)" 4000 --> 11000
|
| 161 |
-
bar [5000, 6000, 7500, 8200, 9500, 10500, 11000, 10200, 9200, 8500, 7000, 6000]
|
| 162 |
-
line [5000, 6000, 7500, 8200, 9500, 10500, 11000, 10200, 9200, 8500, 7000, 6000]
|
| 163 |
-
|
| 164 |
-- flowchart --
|
| 165 |
Important:
|
| 166 |
- If the flow is "broader" than deep (>3 branches at the same level), choose LR (Left Right)
|
|
@@ -708,17 +700,12 @@ def generate_final_report(initial_query: str, context: str, reportstyle: str, le
|
|
| 708 |
word_count = pages * 500
|
| 709 |
prompt = (f"""
|
| 710 |
// Instructions:
|
| 711 |
-
|
| 712 |
-
- Explicit mentions of organizations, tools, projects, or people from the crumb data as possible.
|
| 713 |
-
- In your writing, do the following:
|
| 714 |
-
1. Integrate numbers, quotes, and factual references systematically.
|
| 715 |
2. Whenever you mention a figure or quote, add an inline reference [x] matching its source from the references.
|
| 716 |
3. Specifically name relevant organizations, tools, project names, and people encountered in the crumbs or learnings.
|
| 717 |
-
|
| 718 |
-
|
| 719 |
-
|
| 720 |
-
|
| 721 |
-
|
| 722 |
// Sources
|
| 723 |
Use the following learnings and merged reference details from a deep research process on:
|
| 724 |
'{initial_query}'
|
|
@@ -729,14 +716,14 @@ Produce a comprehensive research report in html format.
|
|
| 729 |
The report should be very detailed and lengthy — approximately the equivalent of {pages} pages (or {word_count} words) when printed.
|
| 730 |
|
| 731 |
// Requirements
|
| 732 |
-
- It must include inline citations (e.g., [1], [2], etc.) from real sources in the
|
| 733 |
-
-
|
| 734 |
- Don't make too large blocks, skip lines and add line breaks when changing topic.
|
| 735 |
-
- name projects, products, organisations and people with their titles - make it REAL
|
| 736 |
- The report must include at least {round(pages/3,0)} tables from the sources used (add citations if necessary) and use facts and figures extensively to ground the analysis.
|
| 737 |
- For the numbering of titles or numbered lists, use numbers (ex: 1.) and sub-units (1.1, 1.2... 1.1.1...,1.1.2...).
|
|
|
|
| 738 |
- For the reference citations, add systematically the urls from the Learnings (no need to put them in numbered list format since we alredy have the [x] that serves as number list)
|
| 739 |
-
|
| 740 |
- Put paragraphs, sentences that are part of the same section in a div tag, this will be used for formatting.
|
| 741 |
- Text Alignment has to be to the left, including for the titles
|
| 742 |
- Add on top of the report the report title (with the <h1> tag) - this is the only part that should be centered (in-line style)
|
|
@@ -747,10 +734,13 @@ IMPORTANT: Do not make false references / citations. It has to be grounded from
|
|
| 747 |
<h4> for bulletpoint title (ex: <h4>item to detail:</h4>details ...)
|
| 748 |
- Use inline formatting for the tables with homogeneous border and colors
|
| 749 |
- Avoid Chinese characters in the output (use the Pinyin version) since they won't display correcly in the pdf (black boxes)
|
| 750 |
-
|
|
|
|
|
|
|
|
|
|
| 751 |
|
| 752 |
// Visual placeholders
|
| 753 |
-
- Since the generation of visuals (excluding tables)
|
| 754 |
[[Visual Placeholder n:
|
| 755 |
- Purpose of this visual is:...
|
| 756 |
- Relevant data to generate it:...
|
|
@@ -758,37 +748,34 @@ IMPORTANT: Do not make false references / citations. It has to be grounded from
|
|
| 758 |
with n as the reference number
|
| 759 |
Important: after [[ put "Visual Placeholder n:" explicitly (with n as the ref number of the focus box created). This will be used in a regex
|
| 760 |
|
| 761 |
-
- the only types of mermaid diagram that can be generated are: flowchart, sequence, gantt, pie, mindmap
|
| 762 |
- do not make reference in the report to "visual placeholders" just mention visuals.
|
| 763 |
-
- in the placeholder, no need to add the references to the source, but make sure ALL of the data points required has a source from the learning and reference material hereafter
|
| 764 |
- these placeholders text should contain:
|
| 765 |
o the purpose of the future visual
|
| 766 |
o the relevant data to generate it
|
| 767 |
-
- there should be at least {round(pages/4,0)} of these visuals placeholders within the report
|
| 768 |
-
- 2 visual placeholders cannot be in the same
|
| 769 |
-
Note: the placeholders will then be processed
|
| 770 |
|
| 771 |
// Graph placeholders
|
| 772 |
-
- Create special
|
| 773 |
[[Graph Placeholder n:
|
| 774 |
- Purpose of this graph is:...
|
| 775 |
- Relevant data to generate it:...
|
| 776 |
-
- Visual guidance:...
|
| 777 |
]]
|
| 778 |
with n as the reference number
|
| 779 |
Important: after [[ put "Graph Placeholder n:" explicitly (with n as the ref number of the focus box created). This will be used in a regex
|
| 780 |
|
| 781 |
-
- All types of graphs
|
| 782 |
- do not make mention in the report to "graph placeholders" just mention graph.
|
| 783 |
-
- in the placeholder, no need to add the references to the source, but make sure ALL of the data points required has a source from the learning and reference material hereafter
|
| 784 |
- these placeholders text should contain:
|
| 785 |
o the purpose of the future graph
|
| 786 |
o the relevant data to generate it
|
| 787 |
-
|
| 788 |
-
|
| 789 |
-
|
| 790 |
-
- 2 graph placeholders cannot be in the same or in 2 consecutive sections
|
| 791 |
-
Note: the placeholders will then be processed separtely by a llm to generate the specific code to display each of them so the instruction need to be clear enough.
|
| 792 |
|
| 793 |
// Focus placeholders
|
| 794 |
- To drill down on specific topic that would be deserve to be developped extensively separately, create special focus placeholders in [[...]] double backets
|
|
@@ -802,12 +789,12 @@ Note: outside of the placeholder, do not make reference in the report to "focus
|
|
| 802 |
- these placeholders text should contain:
|
| 803 |
o the purpose of the focus box
|
| 804 |
o the relevant data to generate it
|
| 805 |
-
o the guidance in terms of style and message to
|
| 806 |
-
|
| 807 |
-
- there should be {round(pages/6,0)} of these focus placeholders within the report
|
| 808 |
-
- 2 focus placeholders cannot be in the same
|
| 809 |
-
-
|
| 810 |
-
Note: the placeholders will then be processed
|
| 811 |
|
| 812 |
// Format:
|
| 813 |
[[Focus Placeholder n:
|
|
@@ -823,10 +810,10 @@ Important: after [[ put "Focus Placeholder n:" explicitly (with n as the ref num
|
|
| 823 |
- Abstract
|
| 824 |
- Table of contents (do not mention the pages)
|
| 825 |
- Introduction
|
| 826 |
-
- [Sections and sub-sections, depending on the size and relevant topic - including visual and focus placeholders]
|
| 827 |
- Conclusion
|
| 828 |
- References of the documents used in the inline citations
|
| 829 |
-
Important: placeholders (visual, graph or focus) can only appear in the sections or sub-sections not in introduction, the conclusion, the references or after the
|
| 830 |
|
| 831 |
Output the report directly without any introductory meta comments.
|
| 832 |
|
|
|
|
| 35 |
|
| 36 |
def generate_graph_snippet(placeholder_text: str, context: str, initial_query: str, crumbs: str) -> str:
|
| 37 |
prompt = f"""
|
| 38 |
+
Generate a full html code (including css and javascript) code displaying a simple but effective and elegant graph based on the following requirements:
|
| 39 |
{placeholder_text}
|
| 40 |
|
| 41 |
It will be integrated in a broader report (focus on the graph formatting though) about:
|
|
|
|
| 127 |
{crumbs}
|
| 128 |
|
| 129 |
// Requirements
|
| 130 |
+
- use standard mermaid visual rendering (ex: flowchart, sequence, gantt, pie, mindmap)
|
| 131 |
- no introduction, conclusions or code fences -> Output the result directly
|
| 132 |
- create only the content for the mermaid
|
| 133 |
- no comments of #color coding and classes inside the mermaid code generated, it's supposed to be only focused on the mermaid code required to render it
|
|
|
|
| 144 |
G --> H[Performance Evaluation - 45% Speed Improvement, 35% Risk Profiling, 50% Fraud Detection]
|
| 145 |
- Similarly, do not use the symbol | in the mermaid code, it would create an error
|
| 146 |
- Do not use the gantt chart visual placeholder to generate a graph (ex: barchart), Gantt charts should only be used for timelines / project plans
|
| 147 |
+
Note: Visual placeholders are solely supposed to generate diagrams not for graphs.
|
| 148 |
- use only this type of quotation marks: ", others would lead to failure to render
|
| 149 |
- if you need to render a quotation mark inside the text of the diagram make sure to add escapechar so that mermaid interprets it correctly
|
| 150 |
- do not use commas in the content of each object / nodes, they will create rendering issues
|
|
|
|
| 153 |
// Examples
|
| 154 |
Note: Pay attention for each example to what type of parenthesis / bracket is used and respect it scrupulously
|
| 155 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 156 |
-- flowchart --
|
| 157 |
Important:
|
| 158 |
- If the flow is "broader" than deep (>3 branches at the same level), choose LR (Left Right)
|
|
|
|
| 700 |
word_count = pages * 500
|
| 701 |
prompt = (f"""
|
| 702 |
// Instructions:
|
| 703 |
+
1. Integrate numbers, quotes, and factual references systematically (We want to incorporate as many relevant numbers, statistics, factual references, quotes from the sources)
|
|
|
|
|
|
|
|
|
|
| 704 |
2. Whenever you mention a figure or quote, add an inline reference [x] matching its source from the references.
|
| 705 |
3. Specifically name relevant organizations, tools, project names, and people encountered in the crumbs or learnings.
|
| 706 |
+
Note: This is for academic purposes, so thorough citations and referencing are essential.
|
| 707 |
+
4. Focus on reputable sources that will not be disputed (social media posts cannot be an opposable sources, but some of them may mention reputable sources)
|
| 708 |
+
5. It must follow this writing style {reportstyle}.
|
|
|
|
|
|
|
| 709 |
// Sources
|
| 710 |
Use the following learnings and merged reference details from a deep research process on:
|
| 711 |
'{initial_query}'
|
|
|
|
| 716 |
The report should be very detailed and lengthy — approximately the equivalent of {pages} pages (or {word_count} words) when printed.
|
| 717 |
|
| 718 |
// Requirements
|
| 719 |
+
- It must include inline citations (e.g., [1], [2], etc.) from real sources provided in the search results below
|
| 720 |
+
- Do not add any inline citations reference in the placeholders descriptions below (visual, graph or focus)
|
| 721 |
- Don't make too large blocks, skip lines and add line breaks when changing topic.
|
|
|
|
| 722 |
- The report must include at least {round(pages/3,0)} tables from the sources used (add citations if necessary) and use facts and figures extensively to ground the analysis.
|
| 723 |
- For the numbering of titles or numbered lists, use numbers (ex: 1.) and sub-units (1.1, 1.2... 1.1.1...,1.1.2...).
|
| 724 |
+
Note: Exclude the use of html numbered lists format, they don't get correctly implemented. Use plain text format for numbering of sections and sub-sections
|
| 725 |
- For the reference citations, add systematically the urls from the Learnings (no need to put them in numbered list format since we alredy have the [x] that serves as number list)
|
| 726 |
+
- Do not make false references / citations. It has to be grounded from the sources from the results of the searches below (no example.com/... type references!)
|
| 727 |
- Put paragraphs, sentences that are part of the same section in a div tag, this will be used for formatting.
|
| 728 |
- Text Alignment has to be to the left, including for the titles
|
| 729 |
- Add on top of the report the report title (with the <h1> tag) - this is the only part that should be centered (in-line style)
|
|
|
|
| 734 |
<h4> for bulletpoint title (ex: <h4>item to detail:</h4>details ...)
|
| 735 |
- Use inline formatting for the tables with homogeneous border and colors
|
| 736 |
- Avoid Chinese characters in the output (use the Pinyin version) since they won't display correcly in the pdf (black boxes)
|
| 737 |
+
|
| 738 |
+
--------------- Placeholders -----------
|
| 739 |
+
In order to enrich the content, within the core sections (between introduction and conclusion), you can inject some placeholders that will be developped later on.
|
| 740 |
+
There are 3 types: visual, graphs, focus - each with their own purpose
|
| 741 |
|
| 742 |
// Visual placeholders
|
| 743 |
+
- Since the generation of visuals (excluding tables) cannot be done through text, create special visual placeholders that will be rendered in mermaid afterwards based on your guidance:
|
| 744 |
[[Visual Placeholder n:
|
| 745 |
- Purpose of this visual is:...
|
| 746 |
- Relevant data to generate it:...
|
|
|
|
| 748 |
with n as the reference number
|
| 749 |
Important: after [[ put "Visual Placeholder n:" explicitly (with n as the ref number of the focus box created). This will be used in a regex
|
| 750 |
|
| 751 |
+
- the only types of mermaid diagram that can be generated are: flowchart, sequence, gantt, pie, mindmap (no charts) // Take this into consideration when providing the instructions for the diagram
|
| 752 |
- do not make reference in the report to "visual placeholders" just mention visuals.
|
| 753 |
+
- in the placeholder, no need to add the references to the source or its ref number, but make sure ALL of the data points required has a source from the learning and reference material hereafter
|
| 754 |
- these placeholders text should contain:
|
| 755 |
o the purpose of the future visual
|
| 756 |
o the relevant data to generate it
|
| 757 |
+
- there should be at least {round(pages/4,0)} of these visuals placeholders within the report (all between introduction and conclusion)
|
| 758 |
+
- 2 visual placeholders cannot be in the same section
|
| 759 |
+
Note: the placeholders will then be processed separately by a llm to generate the specific code to display each of them so the instruction need to be clear enough.
|
| 760 |
|
| 761 |
// Graph placeholders
|
| 762 |
+
- Create special graph placeholders that will be rendered in d3.js afterwards based on your guidance:
|
| 763 |
[[Graph Placeholder n:
|
| 764 |
- Purpose of this graph is:...
|
| 765 |
- Relevant data to generate it:...
|
|
|
|
| 766 |
]]
|
| 767 |
with n as the reference number
|
| 768 |
Important: after [[ put "Graph Placeholder n:" explicitly (with n as the ref number of the focus box created). This will be used in a regex
|
| 769 |
|
| 770 |
+
- All types of graphs (using d3.js library) can be generated // Take this into consideration when providing the instructions for the graph data
|
| 771 |
- do not make mention in the report to "graph placeholders" just mention graph.
|
| 772 |
+
- in the placeholder, no need to add the references to the source or its ref number, but make sure ALL of the data points required has a source from the learning and reference material hereafter
|
| 773 |
- these placeholders text should contain:
|
| 774 |
o the purpose of the future graph
|
| 775 |
o the relevant data to generate it
|
| 776 |
+
- there should be at least {round(pages/4,0)} of these graphs placeholders within the report (all between introduction and conclusion)
|
| 777 |
+
- 2 graph placeholders cannot be in the same section
|
| 778 |
+
Note: the placeholders will then be processed separately by a llm to generate the specific code to display each of them so the instruction need to be clear enough.
|
|
|
|
|
|
|
| 779 |
|
| 780 |
// Focus placeholders
|
| 781 |
- To drill down on specific topic that would be deserve to be developped extensively separately, create special focus placeholders in [[...]] double backets
|
|
|
|
| 789 |
- these placeholders text should contain:
|
| 790 |
o the purpose of the focus box
|
| 791 |
o the relevant data to generate it
|
| 792 |
+
o the guidance in terms of style and message to convey
|
| 793 |
+
Note: Be specific if you want some particular point developped, keep it consistent across the report.
|
| 794 |
+
- there should be {round(pages/6,0)} of these focus placeholders within the report (all between introduction and conclusion)
|
| 795 |
+
- 2 focus placeholders cannot be in the same section
|
| 796 |
+
- Tip: Use the placeholders for topics that cannot be developped but could be developped later independently, so that you can focus on others.
|
| 797 |
+
Note: the placeholders will then be processed separately by a llm to generate the specific code to display each of them so the instruction need to be clear enough.
|
| 798 |
|
| 799 |
// Format:
|
| 800 |
[[Focus Placeholder n:
|
|
|
|
| 810 |
- Abstract
|
| 811 |
- Table of contents (do not mention the pages)
|
| 812 |
- Introduction
|
| 813 |
+
- [Sections and sub-sections, depending on the size and relevant topic - including visual, graph and focus placeholders]
|
| 814 |
- Conclusion
|
| 815 |
- References of the documents used in the inline citations
|
| 816 |
+
Important: placeholders (visual, graph or focus) can only appear in the sections or sub-sections not in introduction, the conclusion, the references or after the references
|
| 817 |
|
| 818 |
Output the report directly without any introductory meta comments.
|
| 819 |
|