Spaces:
Paused
Paused
Update app.py
Browse files
app.py
CHANGED
@@ -4,6 +4,7 @@ import os
|
|
4 |
import threading
|
5 |
import time
|
6 |
from typing import List, Tuple
|
|
|
7 |
|
8 |
import dash
|
9 |
import dash_bootstrap_components as dbc
|
@@ -36,25 +37,32 @@ def process_document(contents: str, filename: str) -> str:
|
|
36 |
|
37 |
return text
|
38 |
|
39 |
-
def generate_outline(text: str) -> str:
|
40 |
prompt = f"""
|
41 |
Analyze the following Project Work Statement (PWS) and create an outline
|
42 |
focusing on sections L&M. Extract the main headers, subheaders, and specific
|
43 |
-
requirements in each section.
|
|
|
44 |
|
|
|
|
|
|
|
45 |
{text}
|
46 |
|
47 |
-
Provide the outline in a structured format
|
|
|
48 |
"""
|
49 |
response = model.generate_content(prompt)
|
50 |
return response.text
|
51 |
|
52 |
-
def generate_pink_team_document(outline: str) -> str:
|
53 |
prompt = f"""
|
54 |
Based on the following outline of a Project Work Statement (PWS):
|
55 |
|
56 |
{outline}
|
57 |
|
|
|
|
|
58 |
Create a detailed response document as if MicroHealth is responding to this PWS.
|
59 |
Follow these guidelines:
|
60 |
1. Use Wikipedia style writing with active voice.
|
@@ -74,6 +82,11 @@ app.layout = dbc.Container([
|
|
74 |
html.H1("MicroHealth PWS Analysis and Response Generator", className="my-4"),
|
75 |
dbc.Tabs([
|
76 |
dbc.Tab(label="Shred", tab_id="shred", children=[
|
|
|
|
|
|
|
|
|
|
|
77 |
dcc.Upload(
|
78 |
id='upload-document',
|
79 |
children=html.Div(['Drag and Drop or ', html.A('Select Files')]),
|
@@ -94,6 +107,11 @@ app.layout = dbc.Container([
|
|
94 |
dcc.Download(id="download-shred-doc")
|
95 |
]),
|
96 |
dbc.Tab(label="Pink", tab_id="pink", children=[
|
|
|
|
|
|
|
|
|
|
|
97 |
dbc.Button("Generate Pink Team Document", id="generate-pink", className="mt-3"),
|
98 |
dbc.Spinner(html.Div(id='pink-output')),
|
99 |
dbc.Button("Download Pink Team Document", id="download-pink", className="mt-3"),
|
@@ -105,26 +123,28 @@ app.layout = dbc.Container([
|
|
105 |
@app.callback(
|
106 |
Output('shred-output', 'children'),
|
107 |
Input('upload-document', 'contents'),
|
108 |
-
State('upload-document', 'filename')
|
|
|
109 |
)
|
110 |
-
def update_shred_output(contents, filename):
|
111 |
if contents is None:
|
112 |
return "Upload a document to begin."
|
113 |
|
114 |
text = process_document(contents, filename)
|
115 |
-
outline = generate_outline(text)
|
116 |
return dcc.Markdown(outline)
|
117 |
|
118 |
@app.callback(
|
119 |
Output('pink-output', 'children'),
|
120 |
Input('generate-pink', 'n_clicks'),
|
121 |
-
State('shred-output', 'children')
|
|
|
122 |
)
|
123 |
-
def update_pink_output(n_clicks, shred_output):
|
124 |
if n_clicks is None or shred_output is None:
|
125 |
return "Generate an outline in the Shred tab first."
|
126 |
|
127 |
-
pink_doc = generate_pink_team_document(shred_output)
|
128 |
return dcc.Markdown(pink_doc)
|
129 |
|
130 |
@app.callback(
|
|
|
4 |
import threading
|
5 |
import time
|
6 |
from typing import List, Tuple
|
7 |
+
import re
|
8 |
|
9 |
import dash
|
10 |
import dash_bootstrap_components as dbc
|
|
|
37 |
|
38 |
return text
|
39 |
|
40 |
+
def generate_outline(text: str, instructions: str) -> str:
|
41 |
prompt = f"""
|
42 |
Analyze the following Project Work Statement (PWS) and create an outline
|
43 |
focusing on sections L&M. Extract the main headers, subheaders, and specific
|
44 |
+
requirements in each section. Pay special attention to requirements indicated
|
45 |
+
by words like "shall", "will", "must", and similar imperative language.
|
46 |
|
47 |
+
Additional instructions: {instructions}
|
48 |
+
|
49 |
+
Document text:
|
50 |
{text}
|
51 |
|
52 |
+
Provide the outline in a structured format, clearly highlighting the specific
|
53 |
+
requirements and their associated sections.
|
54 |
"""
|
55 |
response = model.generate_content(prompt)
|
56 |
return response.text
|
57 |
|
58 |
+
def generate_pink_team_document(outline: str, instructions: str) -> str:
|
59 |
prompt = f"""
|
60 |
Based on the following outline of a Project Work Statement (PWS):
|
61 |
|
62 |
{outline}
|
63 |
|
64 |
+
Additional instructions: {instructions}
|
65 |
+
|
66 |
Create a detailed response document as if MicroHealth is responding to this PWS.
|
67 |
Follow these guidelines:
|
68 |
1. Use Wikipedia style writing with active voice.
|
|
|
82 |
html.H1("MicroHealth PWS Analysis and Response Generator", className="my-4"),
|
83 |
dbc.Tabs([
|
84 |
dbc.Tab(label="Shred", tab_id="shred", children=[
|
85 |
+
dbc.Textarea(
|
86 |
+
id='shred-instructions',
|
87 |
+
placeholder="Enter any additional instructions for shredding the document...",
|
88 |
+
style={'height': '100px', 'marginBottom': '10px'}
|
89 |
+
),
|
90 |
dcc.Upload(
|
91 |
id='upload-document',
|
92 |
children=html.Div(['Drag and Drop or ', html.A('Select Files')]),
|
|
|
107 |
dcc.Download(id="download-shred-doc")
|
108 |
]),
|
109 |
dbc.Tab(label="Pink", tab_id="pink", children=[
|
110 |
+
dbc.Textarea(
|
111 |
+
id='pink-instructions',
|
112 |
+
placeholder="Enter any additional instructions for generating the Pink Team document...",
|
113 |
+
style={'height': '100px', 'marginBottom': '10px'}
|
114 |
+
),
|
115 |
dbc.Button("Generate Pink Team Document", id="generate-pink", className="mt-3"),
|
116 |
dbc.Spinner(html.Div(id='pink-output')),
|
117 |
dbc.Button("Download Pink Team Document", id="download-pink", className="mt-3"),
|
|
|
123 |
@app.callback(
|
124 |
Output('shred-output', 'children'),
|
125 |
Input('upload-document', 'contents'),
|
126 |
+
State('upload-document', 'filename'),
|
127 |
+
State('shred-instructions', 'value')
|
128 |
)
|
129 |
+
def update_shred_output(contents, filename, instructions):
|
130 |
if contents is None:
|
131 |
return "Upload a document to begin."
|
132 |
|
133 |
text = process_document(contents, filename)
|
134 |
+
outline = generate_outline(text, instructions or "")
|
135 |
return dcc.Markdown(outline)
|
136 |
|
137 |
@app.callback(
|
138 |
Output('pink-output', 'children'),
|
139 |
Input('generate-pink', 'n_clicks'),
|
140 |
+
State('shred-output', 'children'),
|
141 |
+
State('pink-instructions', 'value')
|
142 |
)
|
143 |
+
def update_pink_output(n_clicks, shred_output, instructions):
|
144 |
if n_clicks is None or shred_output is None:
|
145 |
return "Generate an outline in the Shred tab first."
|
146 |
|
147 |
+
pink_doc = generate_pink_team_document(shred_output, instructions or "")
|
148 |
return dcc.Markdown(pink_doc)
|
149 |
|
150 |
@app.callback(
|