Spaces:
Sleeping
Sleeping
Commit
·
c8cbe59
1
Parent(s):
f7d29d7
fixing UI
Browse files- app.py +36 -80
- requirements.txt +7 -7
app.py
CHANGED
|
@@ -93,81 +93,47 @@ def analyze_document(file):
|
|
| 93 |
return "\n".join(summary)
|
| 94 |
else:
|
| 95 |
return "No specific topics detected in document."
|
|
|
|
|
|
|
|
|
|
|
|
|
| 96 |
css = """
|
| 97 |
-
|
| 98 |
-
body {
|
| 99 |
background-color: #1a1a1a !important;
|
| 100 |
color: #f5f5f5 !important;
|
| 101 |
font-family: 'Inter', sans-serif !important;
|
| 102 |
-
margin: 0 !important;
|
| 103 |
-
padding: 0 !important;
|
| 104 |
-
}
|
| 105 |
-
|
| 106 |
-
/* Full width */
|
| 107 |
-
#root, .gradio-container, .main {
|
| 108 |
-
max-width: 100% !important;
|
| 109 |
-
width: 100% !important;
|
| 110 |
-
background-color: #1a1a1a !important;
|
| 111 |
-
margin: 0 !important;
|
| 112 |
-
padding: 0 !important;
|
| 113 |
-
border: none !important;
|
| 114 |
-
box-shadow: none !important;
|
| 115 |
}
|
| 116 |
-
|
| 117 |
-
/* Headings and Labels */
|
| 118 |
h1, h2, h3, label {
|
| 119 |
color: #ff9900 !important;
|
| 120 |
font-weight: 600 !important;
|
| 121 |
}
|
| 122 |
-
|
| 123 |
-
/* Text Inputs */
|
| 124 |
-
textarea, input {
|
| 125 |
background-color: #2a2a2a !important;
|
| 126 |
color: #f5f5f5 !important;
|
| 127 |
border: 1px solid #3a3a3a !important;
|
| 128 |
border-radius: 10px !important;
|
| 129 |
-
padding: 12px !important;
|
| 130 |
}
|
| 131 |
-
|
| 132 |
-
|
| 133 |
-
|
| 134 |
-
|
| 135 |
-
/* Buttons */
|
| 136 |
button {
|
| 137 |
background-color: #ff9900 !important;
|
| 138 |
color: #1a1a1a !important;
|
| 139 |
font-weight: 600 !important;
|
| 140 |
border-radius: 8px !important;
|
| 141 |
border: none !important;
|
| 142 |
-
padding: 8px 16px !important;
|
| 143 |
transition: 0.25s ease-in-out;
|
| 144 |
}
|
| 145 |
button:hover {
|
| 146 |
background-color: #ffb84d !important;
|
| 147 |
}
|
| 148 |
-
|
| 149 |
-
/* Output textbox */
|
| 150 |
.output-textbox {
|
| 151 |
background-color: #252525 !important;
|
| 152 |
color: #ffd480 !important;
|
| 153 |
border: 1px solid #3a3a3a !important;
|
| 154 |
border-radius: 10px !important;
|
| 155 |
-
box-shadow: inset 0 0 6px rgba(255,153,0,0.1);
|
| 156 |
-
}
|
| 157 |
-
|
| 158 |
-
/* Tabs */
|
| 159 |
-
.tabitem.svelte-1ipelgc {
|
| 160 |
-
background-color: #1a1a1a !important;
|
| 161 |
-
color: #ffb84d !important;
|
| 162 |
}
|
| 163 |
-
.
|
| 164 |
-
background-color:
|
| 165 |
-
color: #1a1a1a !important;
|
| 166 |
-
font-weight: 700 !important;
|
| 167 |
}
|
| 168 |
-
|
| 169 |
-
/* Footer */
|
| 170 |
-
.footer, .svelte-1xdkkgx, .wrap.svelte-1ipelgc {
|
| 171 |
background: none !important;
|
| 172 |
border: none !important;
|
| 173 |
box-shadow: none !important;
|
|
@@ -177,43 +143,33 @@ button:hover {
|
|
| 177 |
"""
|
| 178 |
|
| 179 |
# -------------------------
|
| 180 |
-
#
|
| 181 |
# -------------------------
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 182 |
|
| 183 |
-
|
| 184 |
-
|
| 185 |
-
|
| 186 |
-
label="📝 Enter Text",
|
| 187 |
-
placeholder="Type or paste text here...",
|
| 188 |
-
lines=4
|
| 189 |
-
),
|
| 190 |
-
outputs=gr.Textbox(label="🎯 Detected Topics"),
|
| 191 |
-
examples=[
|
| 192 |
-
["Just watched the new Marvel movie, it was amazing!"],
|
| 193 |
-
["Bitcoin prices are going up again!"],
|
| 194 |
-
["Climate change is affecting polar bears."],
|
| 195 |
-
],
|
| 196 |
-
title="💬 Text Topic Analyzer",
|
| 197 |
-
description="Analyze short texts or tweets to detect underlying topics using CardiffNLP’s Tweet Topic model.",
|
| 198 |
-
)
|
| 199 |
-
|
| 200 |
-
document_tab = gr.Interface(
|
| 201 |
-
fn=analyze_document,
|
| 202 |
-
inputs=gr.File(label="📄 Upload Document (PDF, DOCX, or TXT)"),
|
| 203 |
-
outputs=gr.Textbox(label="📘 Detected Topics"),
|
| 204 |
-
title="📄 Document Topic Analyzer",
|
| 205 |
-
description="Upload a document and let the AI detect key topics discussed inside.",
|
| 206 |
-
)
|
| 207 |
-
|
| 208 |
-
app = gr.TabbedInterface(
|
| 209 |
-
[tweet_tab, document_tab],
|
| 210 |
-
["💬 Text Analyzer", "📄 Document Analyzer"],
|
| 211 |
-
title="🧠 AI Topic Analyzer",
|
| 212 |
-
css=css,
|
| 213 |
-
theme=gr.themes.Base(primary_hue="orange", secondary_hue="orange"),
|
| 214 |
-
)
|
| 215 |
-
|
| 216 |
if __name__ == "__main__":
|
| 217 |
-
app.launch()
|
| 218 |
-
|
| 219 |
-
|
|
|
|
| 93 |
return "\n".join(summary)
|
| 94 |
else:
|
| 95 |
return "No specific topics detected in document."
|
| 96 |
+
|
| 97 |
+
# -------------------------
|
| 98 |
+
# Custom CSS for Dark Theme
|
| 99 |
+
# -------------------------
|
| 100 |
css = """
|
| 101 |
+
body, .gradio-container {
|
|
|
|
| 102 |
background-color: #1a1a1a !important;
|
| 103 |
color: #f5f5f5 !important;
|
| 104 |
font-family: 'Inter', sans-serif !important;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 105 |
}
|
|
|
|
|
|
|
| 106 |
h1, h2, h3, label {
|
| 107 |
color: #ff9900 !important;
|
| 108 |
font-weight: 600 !important;
|
| 109 |
}
|
| 110 |
+
textarea, input, .upload-box, .gr-box {
|
|
|
|
|
|
|
| 111 |
background-color: #2a2a2a !important;
|
| 112 |
color: #f5f5f5 !important;
|
| 113 |
border: 1px solid #3a3a3a !important;
|
| 114 |
border-radius: 10px !important;
|
|
|
|
| 115 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 116 |
button {
|
| 117 |
background-color: #ff9900 !important;
|
| 118 |
color: #1a1a1a !important;
|
| 119 |
font-weight: 600 !important;
|
| 120 |
border-radius: 8px !important;
|
| 121 |
border: none !important;
|
|
|
|
| 122 |
transition: 0.25s ease-in-out;
|
| 123 |
}
|
| 124 |
button:hover {
|
| 125 |
background-color: #ffb84d !important;
|
| 126 |
}
|
|
|
|
|
|
|
| 127 |
.output-textbox {
|
| 128 |
background-color: #252525 !important;
|
| 129 |
color: #ffd480 !important;
|
| 130 |
border: 1px solid #3a3a3a !important;
|
| 131 |
border-radius: 10px !important;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 132 |
}
|
| 133 |
+
.gr-tabs, .tabitem {
|
| 134 |
+
background-color: transparent !important;
|
|
|
|
|
|
|
| 135 |
}
|
| 136 |
+
footer, .footer, .svelte-1xdkkgx {
|
|
|
|
|
|
|
| 137 |
background: none !important;
|
| 138 |
border: none !important;
|
| 139 |
box-shadow: none !important;
|
|
|
|
| 143 |
"""
|
| 144 |
|
| 145 |
# -------------------------
|
| 146 |
+
# Layout Using Blocks
|
| 147 |
# -------------------------
|
| 148 |
+
with gr.Blocks(css=css, theme=gr.themes.Base(primary_hue="orange")) as app:
|
| 149 |
+
gr.Markdown("<h1 style='text-align:center;'>🧠 AI Topic Analyzer</h1>")
|
| 150 |
+
gr.Markdown(
|
| 151 |
+
"Analyze text or upload a document to detect key topics using CardiffNLP’s Tweet Topic model."
|
| 152 |
+
)
|
| 153 |
+
|
| 154 |
+
with gr.Tabs():
|
| 155 |
+
with gr.Tab("💬 Text Analyzer"):
|
| 156 |
+
text_input = gr.Textbox(
|
| 157 |
+
label="📝 Enter Text", placeholder="Type or paste text here...", lines=4
|
| 158 |
+
)
|
| 159 |
+
text_output = gr.Textbox(label="🎯 Detected Topics", elem_classes=["output-textbox"])
|
| 160 |
+
analyze_text_btn = gr.Button("Analyze Text")
|
| 161 |
+
analyze_text_btn.click(analyze_topics, inputs=text_input, outputs=text_output)
|
| 162 |
+
|
| 163 |
+
with gr.Tab("📄 Document Analyzer"):
|
| 164 |
+
file_input = gr.File(label="📄 Upload PDF, DOCX, or TXT", file_types=[".pdf", ".docx", ".txt"])
|
| 165 |
+
doc_output = gr.Textbox(label="📘 Detected Topics", elem_classes=["output-textbox"])
|
| 166 |
+
analyze_doc_btn = gr.Button("Analyze Document")
|
| 167 |
+
analyze_doc_btn.click(analyze_document, inputs=file_input, outputs=doc_output)
|
| 168 |
+
|
| 169 |
+
gr.Markdown("<p style='text-align:center; color:#888;'>Built with ❤️ using Gradio & Transformers</p>")
|
| 170 |
|
| 171 |
+
# -------------------------
|
| 172 |
+
# Launch
|
| 173 |
+
# -------------------------
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 174 |
if __name__ == "__main__":
|
| 175 |
+
app.launch()
|
|
|
|
|
|
requirements.txt
CHANGED
|
@@ -1,7 +1,7 @@
|
|
| 1 |
-
gradio
|
| 2 |
-
transformers
|
| 3 |
-
torch
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
|
|
|
| 1 |
+
gradio
|
| 2 |
+
transformers
|
| 3 |
+
torch
|
| 4 |
+
PyPDF2
|
| 5 |
+
python-docx
|
| 6 |
+
numpy
|
| 7 |
+
scipy
|