Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -7,7 +7,7 @@ import json
|
|
| 7 |
import os
|
| 8 |
|
| 9 |
def extract_and_parse_json_from_markdown(markdown_text: str) -> dict:
|
| 10 |
-
code_block_pattern = r"
|
| 11 |
code_block_match = re.search(code_block_pattern, markdown_text)
|
| 12 |
|
| 13 |
if code_block_match:
|
|
@@ -28,32 +28,35 @@ def process_event(event):
|
|
| 28 |
|
| 29 |
|
| 30 |
llm_prompt = f"""
|
|
|
|
| 31 |
You are a digital marketing campaign analyst designed to analyze and report digital marketing campaign data for Rod Wave concerts, Your job is to convert the given text into JSON
|
| 32 |
|
| 33 |
{{
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
| 52 |
}}
|
| 53 |
|
| 54 |
Here is Text for it:
|
|
|
|
| 55 |
{event}
|
| 56 |
|
|
|
|
| 57 |
Return in only JSON adhering to Above Schema
|
| 58 |
"""
|
| 59 |
|
|
@@ -67,25 +70,32 @@ def process_all_events(events):
|
|
| 67 |
json_all = []
|
| 68 |
progress_bar = st.progress(0)
|
| 69 |
|
| 70 |
-
with concurrent.futures.ThreadPoolExecutor(max_workers=
|
| 71 |
futures = [executor.submit(process_event, event) for event in events]
|
| 72 |
|
| 73 |
for i, future in enumerate(concurrent.futures.as_completed(futures)):
|
| 74 |
progress = (i + 1) / len(events)
|
| 75 |
progress_bar.progress(progress)
|
| 76 |
-
st.write(f"Processed event {i + 1}/{len(events)}")
|
| 77 |
json_all.append(future.result())
|
| 78 |
|
| 79 |
return json_all
|
| 80 |
|
|
|
|
| 81 |
def main():
|
| 82 |
st.title("Rod Wave Concert Marketing Data Processor")
|
| 83 |
-
st.write("Upload a text file containing concert marketing data to convert it to CSV format")
|
| 84 |
|
| 85 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 86 |
|
| 87 |
-
if
|
| 88 |
-
text = uploaded_file.read().decode("utf-8")
|
| 89 |
events = re.split(r'\n(?=Rod Wave Concert)', text)
|
| 90 |
events = [event for event in events if event.strip()]
|
| 91 |
|
|
@@ -114,4 +124,4 @@ def main():
|
|
| 114 |
)
|
| 115 |
|
| 116 |
if __name__ == "__main__":
|
| 117 |
-
main()
|
|
|
|
| 7 |
import os
|
| 8 |
|
| 9 |
def extract_and_parse_json_from_markdown(markdown_text: str) -> dict:
|
| 10 |
+
code_block_pattern = r"```(?:json)?\s*([\s\S]*?)```"
|
| 11 |
code_block_match = re.search(code_block_pattern, markdown_text)
|
| 12 |
|
| 13 |
if code_block_match:
|
|
|
|
| 28 |
|
| 29 |
|
| 30 |
llm_prompt = f"""
|
| 31 |
+
|
| 32 |
You are a digital marketing campaign analyst designed to analyze and report digital marketing campaign data for Rod Wave concerts, Your job is to convert the given text into JSON
|
| 33 |
|
| 34 |
{{
|
| 35 |
+
"market": "str",
|
| 36 |
+
"total_spend": "float",
|
| 37 |
+
"impressions": "float",
|
| 38 |
+
"clicks": "float",
|
| 39 |
+
"metrics_cpc": "float",
|
| 40 |
+
"metrics_cpm": "float",
|
| 41 |
+
"metrics_ctr": "float",
|
| 42 |
+
"metrics_cpa": "float",
|
| 43 |
+
"platform_spend_meta_total": "float",
|
| 44 |
+
"platform_spend_meta_instagram": "float",
|
| 45 |
+
"platform_spend_meta_facebook": "float",
|
| 46 |
+
"platform_spend_google_total": "float",
|
| 47 |
+
"platform_spend_google_youtube": "float",
|
| 48 |
+
"platform_spend_google_search_display": "float",
|
| 49 |
+
"platform_spend_programmatic": "float",
|
| 50 |
+
"revenue_average_ticket_price": "float",
|
| 51 |
+
"revenue_total_revenue": "float",
|
| 52 |
+
"revenue_roi": "float"
|
| 53 |
}}
|
| 54 |
|
| 55 |
Here is Text for it:
|
| 56 |
+
|
| 57 |
{event}
|
| 58 |
|
| 59 |
+
|
| 60 |
Return in only JSON adhering to Above Schema
|
| 61 |
"""
|
| 62 |
|
|
|
|
| 70 |
json_all = []
|
| 71 |
progress_bar = st.progress(0)
|
| 72 |
|
| 73 |
+
with concurrent.futures.ThreadPoolExecutor(max_workers=6) as executor:
|
| 74 |
futures = [executor.submit(process_event, event) for event in events]
|
| 75 |
|
| 76 |
for i, future in enumerate(concurrent.futures.as_completed(futures)):
|
| 77 |
progress = (i + 1) / len(events)
|
| 78 |
progress_bar.progress(progress)
|
| 79 |
+
# st.write(f"Processed event {i + 1}/{len(events)}")
|
| 80 |
json_all.append(future.result())
|
| 81 |
|
| 82 |
return json_all
|
| 83 |
|
| 84 |
+
|
| 85 |
def main():
|
| 86 |
st.title("Rod Wave Concert Marketing Data Processor")
|
|
|
|
| 87 |
|
| 88 |
+
input_method = st.radio("Choose input method:", ["Text Area", "File Upload"])
|
| 89 |
+
|
| 90 |
+
text = None
|
| 91 |
+
if input_method == "Text Area":
|
| 92 |
+
text = st.text_area("Enter concert marketing data:", height=300)
|
| 93 |
+
else:
|
| 94 |
+
uploaded_file = st.file_uploader("Choose a text file", type="txt")
|
| 95 |
+
if uploaded_file is not None:
|
| 96 |
+
text = uploaded_file.read().decode("utf-8")
|
| 97 |
|
| 98 |
+
if text:
|
|
|
|
| 99 |
events = re.split(r'\n(?=Rod Wave Concert)', text)
|
| 100 |
events = [event for event in events if event.strip()]
|
| 101 |
|
|
|
|
| 124 |
)
|
| 125 |
|
| 126 |
if __name__ == "__main__":
|
| 127 |
+
main()
|