Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -0,0 +1,78 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
from transformers import pipeline
|
3 |
+
|
4 |
+
MAX_LENGTH = 512
|
5 |
+
|
6 |
+
st.set_page_config(
|
7 |
+
page_title = "Correct spelling mistakes app",
|
8 |
+
page_icon = "🤠",
|
9 |
+
layout = "centered",
|
10 |
+
initial_sidebar_state = "auto"
|
11 |
+
)
|
12 |
+
|
13 |
+
st.markdown(
|
14 |
+
"""
|
15 |
+
<h1 style="text-align: center; color: #4CAF50; font-family: 'Helvetica';">
|
16 |
+
📚 Correct spelling mistakes app
|
17 |
+
</h1>
|
18 |
+
<p style="text-align: center; color: #777; font-size: 18px;">
|
19 |
+
Enter a context to get corrected context powered by AI.
|
20 |
+
</p>
|
21 |
+
""",
|
22 |
+
unsafe_allow_html=True,
|
23 |
+
)
|
24 |
+
|
25 |
+
st.sidebar.header("Model Settings")
|
26 |
+
model_checkpoint = st.sidebar.text_input(
|
27 |
+
"Model Checkpoint", "Diezu/batphocuadieu", help="Specify the model checkpoint to use."
|
28 |
+
)
|
29 |
+
st.sidebar.markdown(
|
30 |
+
"""
|
31 |
+
<small>Using default model: <code>Diezu/batphocuadieu</code>.</small>
|
32 |
+
""",
|
33 |
+
unsafe_allow_html=True,
|
34 |
+
)
|
35 |
+
corrected_spelling = pipeline("text2text-generation", model=model_checkpoint)
|
36 |
+
|
37 |
+
st.markdown(
|
38 |
+
"""
|
39 |
+
<h2 style="color: #2196F3;">Provide Context</h2>
|
40 |
+
""",
|
41 |
+
unsafe_allow_html=True,
|
42 |
+
)
|
43 |
+
context = st.text_area(
|
44 |
+
"Context",
|
45 |
+
"",
|
46 |
+
help="Paste the context where the answer can be found.",
|
47 |
+
height=200,
|
48 |
+
placeholder="Enter your context here...",
|
49 |
+
)
|
50 |
+
|
51 |
+
if st.button("Get Answer"):
|
52 |
+
if context.strip() == "":
|
53 |
+
st.warning("Please provide context!")
|
54 |
+
else:
|
55 |
+
try:
|
56 |
+
result = corrected_spelling(context,max_length = MAX_LENGTH)
|
57 |
+
st.success("Answer Correct!")
|
58 |
+
st.markdown(
|
59 |
+
f"""
|
60 |
+
<div style="background-color: #f1f8ff; border-left: 4px solid #2196F3; padding: 10px; margin-top: 10px;">
|
61 |
+
<strong>Answer:</strong> {result['answer']}
|
62 |
+
</div>
|
63 |
+
""",
|
64 |
+
unsafe_allow_html=True,
|
65 |
+
)
|
66 |
+
except Exception as e:
|
67 |
+
st.error(f"Error: {e}")
|
68 |
+
|
69 |
+
st.markdown(
|
70 |
+
"""
|
71 |
+
<hr>
|
72 |
+
<footer style="text-align: center; font-size: small; color: #888;">
|
73 |
+
Built with ❤️ using <strong>Streamlit</strong> and <strong>Transformers</strong>.
|
74 |
+
</footer>
|
75 |
+
""",
|
76 |
+
unsafe_allow_html=True,
|
77 |
+
)
|
78 |
+
|