mibrahimzia commited on
Commit
81f3efd
Β·
verified Β·
1 Parent(s): d15f059

Update utils/ui_helpers.py

Browse files
Files changed (1) hide show
  1. utils/ui_helpers.py +19 -64
utils/ui_helpers.py CHANGED
@@ -1,67 +1,22 @@
1
  import streamlit as st
2
- import pandas as pd
3
 
4
- def display_results(data, content_type):
5
- """Display extraction results in Streamlit UI"""
6
- st.success("βœ… Content extracted successfully!")
7
-
8
- # Metadata section
9
- with st.expander("πŸ“Š Metadata", expanded=True):
10
- col1, col2, col3 = st.columns(3)
11
- col1.metric("Status Code", data["metadata"]["status_code"])
12
- col2.metric("Content Type", content_type)
13
- col3.metric("Timestamp", data["metadata"]["timestamp"])
14
-
15
- # Content sections based on what was extracted
16
- if "article" in data["content"]:
17
- with st.expander("πŸ“ Article Content", expanded=True):
18
- st.subheader(data["content"]["article"]["title"])
19
- st.write(data["content"]["article"]["content"])
20
-
21
- if "text" in data["content"]:
22
- with st.expander("πŸ“„ Text Content"):
23
- for i, text in enumerate(data["content"]["text"][:10]): # Show first 10 paragraphs
24
- st.write(text)
25
- if i < len(data["content"]["text"][:10]) - 1:
26
- st.divider()
27
-
28
- if "images" in data["content"] and data["content"]["images"]:
29
- with st.expander("πŸ–ΌοΈ Images"):
30
- for img in data["content"]["images"][:5]: # Show first 5 images
31
- st.image(img["src"], caption=img["alt"], use_column_width=True)
32
-
33
- if "links" in data["content"] and data["content"]["links"]:
34
- with st.expander("πŸ”— Links"):
35
- links_df = pd.DataFrame(data["content"]["links"])
36
- st.dataframe(links_df[["text", "href"]].head(10)) # Show first 10 links
37
-
38
- if "custom" in data["content"] and data["content"]["custom"]:
39
- with st.expander("🎯 Custom Elements"):
40
- for element in data["content"]["custom"]:
41
- st.write(f"**Selector**: `{element['selector']}`")
42
- st.write(f"**Text**: {element['text']}")
43
- st.divider()
44
 
45
- def render_content(content_type, data):
46
- """Render content in a type-specific way"""
47
- if content_type == "quotes":
48
- render_quotes(data)
49
- elif content_type == "newsletter":
50
- render_newsletter(data)
51
-
52
- def render_quotes(data):
53
- """Specialized rendering for quotes"""
54
- if "custom" in data["content"]:
55
- st.subheader("πŸ’¬ Extracted Quotes")
56
- for element in data["content"]["custom"]:
57
- if "quote" in element["selector"]:
58
- st.info(f'"{element["text"]}"')
59
- st.divider()
60
-
61
- def render_newsletter(data):
62
- """Specialized rendering for news content"""
63
- if "custom" in data["content"]:
64
- st.subheader("πŸ“° News Headlines")
65
- for element in data["content"]["custom"]:
66
- if any(sel in element["selector"] for sel in [".title", ".storylink"]):
67
- st.write(f"β€’ {element['text']}")
 
1
  import streamlit as st
 
2
 
3
+ def styled_container(title, content):
4
+ return st.markdown(f"""
5
+ <div class="card">
6
+ <h3>{title}</h3>
7
+ {content}
8
+ </div>
9
+ """, unsafe_allow_html=True)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
10
 
11
+ def render_footer():
12
+ st.divider()
13
+ st.markdown("""
14
+ <div style="text-align: center; padding: 1.5rem; color: #666;">
15
+ <p>Built with ❀️ using Python, FastAPI, and Streamlit</p>
16
+ <p>
17
+ <a href="https://github.com/yourusername/webtapi" target="_blank">GitHub</a> |
18
+ <a href="https://huggingface.co/spaces" target="_blank">Hugging Face</a> |
19
+ AGPL-3.0 License
20
+ </p>
21
+ </div>
22
+ """, unsafe_allow_html=True)