awinml commited on
Commit
77e4580
Β·
verified Β·
1 Parent(s): ff417c7

Update src/streamlit_app.py

Browse files
Files changed (1) hide show
  1. src/streamlit_app.py +93 -32
src/streamlit_app.py CHANGED
@@ -1,40 +1,101 @@
1
- import altair as alt
2
- import numpy as np
3
- import pandas as pd
4
  import streamlit as st
 
 
5
 
6
- """
7
- # Welcome to Streamlit!
 
 
 
 
8
 
9
- Edit `/streamlit_app.py` to customize this app to your heart's desire :heart:.
10
- If you have any questions, checkout our [documentation](https://docs.streamlit.io) and [community
11
- forums](https://discuss.streamlit.io).
 
12
 
13
- In the meantime, below is an example of what you can do with just a few lines of code:
14
- """
 
 
 
 
15
 
16
- num_points = st.slider("Number of points in spiral", 1, 10000, 1100)
17
- num_turns = st.slider("Number of turns in spiral", 1, 300, 31)
18
 
19
- indices = np.linspace(0, 1, num_points)
20
- theta = 2 * np.pi * num_turns * indices
21
- radius = indices
 
 
 
 
 
 
22
 
23
- x = radius * np.cos(theta)
24
- y = radius * np.sin(theta)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
25
 
26
- df = pd.DataFrame({
27
- "x": x,
28
- "y": y,
29
- "idx": indices,
30
- "rand": np.random.randn(num_points),
31
- })
32
-
33
- st.altair_chart(alt.Chart(df, height=700, width=700)
34
- .mark_point(filled=True)
35
- .encode(
36
- x=alt.X("x", axis=None),
37
- y=alt.Y("y", axis=None),
38
- color=alt.Color("idx", legend=None, scale=alt.Scale()),
39
- size=alt.Size("rand", legend=None, scale=alt.Scale(range=[1, 150])),
40
- ))
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  import streamlit as st
2
+ from markdown_it import MarkdownIt
3
+ from mdit_plain.renderer import RendererPlain
4
 
5
+ # Configure the page
6
+ st.set_page_config(
7
+ page_title="Markdown to Plain Text Converter",
8
+ page_icon="πŸ“",
9
+ layout="wide"
10
+ )
11
 
12
+ # Initialize the markdown parser
13
+ @st.cache_resource
14
+ def get_parser():
15
+ return MarkdownIt(renderer_cls=RendererPlain)
16
 
17
+ # App title and description
18
+ st.title("πŸ“ Markdown to Plain Text Converter")
19
+ st.markdown("""
20
+ Convert your markdown text to plain text. Paste your markdown in the left box,
21
+ click convert, and copy the plain text from the right box.
22
+ """)
23
 
24
+ # Create two columns
25
+ col1, col2 = st.columns(2)
26
 
27
+ # Left column - Markdown input
28
+ with col1:
29
+ st.subheader("Markdown Input")
30
+ markdown_input = st.text_area(
31
+ "Paste your markdown here:",
32
+ height=400,
33
+ placeholder="# Heading\n\nThis is **bold** and this is *italic*.\n\n- List item 1\n- List item 2\n\n[This is a link](https://example.com)",
34
+ label_visibility="collapsed"
35
+ )
36
 
37
+ # Right column - Plain text output
38
+ with col2:
39
+ st.subheader("Plain Text Output")
40
+
41
+ if st.button("Convert", type="primary", use_container_width=True):
42
+ if markdown_input.strip():
43
+ try:
44
+ parser = get_parser()
45
+ plain_text = parser.render(markdown_input)
46
+
47
+ # Display the converted text in a text area
48
+ plain_text_output = st.text_area(
49
+ "Converted plain text:",
50
+ value=plain_text,
51
+ height=400,
52
+ label_visibility="collapsed"
53
+ )
54
+
55
+ # Add copy button
56
+ if plain_text_output:
57
+ st.button(
58
+ "Copy to Clipboard",
59
+ key="copy_button",
60
+ use_container_width=True,
61
+ on_click=lambda: st.write("πŸ“‹ Text copied to clipboard! Select and copy the text above.")
62
+ )
63
+
64
+ except Exception as e:
65
+ st.error(f"Error converting markdown: {str(e)}")
66
+ else:
67
+ st.warning("Please enter some markdown text to convert.")
68
 
69
+ # Add some examples
70
+ with st.expander("πŸ’‘ Examples"):
71
+ st.markdown("""
72
+ **Markdown Input:**
73
+ ```
74
+ # Main Heading
75
+
76
+ This is a paragraph with **bold** and *italic* text.
77
+
78
+ ## Subheading
79
+
80
+ - List item 1
81
+ - List item 2
82
+ - List item 3
83
+
84
+ [Visit Google](https://google.com)
85
+ ```
86
+
87
+ **Plain Text Output:**
88
+ ```
89
+ Main Heading
90
+
91
+ This is a paragraph with bold and italic text.
92
+
93
+ Subheading
94
+
95
+ List item 1
96
+ List item 2
97
+ List item 3
98
+
99
+ Visit Google (https://google.com)
100
+ ```
101
+ """)