Spaces:
Sleeping
Sleeping
Commit Β·
ec63772
1
Parent(s): 4b45834
Fix Gradio version compatibility issues
Browse files- src/app.py +60 -90
src/app.py
CHANGED
|
@@ -1,11 +1,9 @@
|
|
| 1 |
-
from urllib import response
|
| 2 |
-
|
| 3 |
import gradio as gr
|
| 4 |
from src.features.translation import translate_text
|
| 5 |
from src.features.summarization import summarize_text
|
| 6 |
from src.features.keyword_extraction import extract_keywords
|
| 7 |
from src.features.email_writer import write_email, write_cover_letter
|
| 8 |
-
from src.features.pdf_qa import
|
| 9 |
from src.graphs.chat_graph import ChatSession
|
| 10 |
|
| 11 |
chat_session = ChatSession()
|
|
@@ -19,36 +17,25 @@ LANGUAGES = [
|
|
| 19 |
|
| 20 |
custom_css = """
|
| 21 |
:root {
|
| 22 |
-
--primary: #
|
| 23 |
-
--primary-light: #
|
| 24 |
--surface: #ffffff;
|
| 25 |
-
--surface-2: #
|
| 26 |
-
--border: #
|
| 27 |
-
--text: #
|
| 28 |
-
--text-muted: #
|
| 29 |
-
--success: #00b894;
|
| 30 |
--radius: 16px;
|
| 31 |
--radius-sm: 10px;
|
| 32 |
-
--shadow: 0 4px 24px rgba(
|
| 33 |
-
|
| 34 |
}
|
| 35 |
|
| 36 |
body, .gradio-container {
|
| 37 |
-
background: linear-gradient(135deg, #
|
| 38 |
font-family: 'Inter', 'Segoe UI', sans-serif !important;
|
| 39 |
}
|
| 40 |
|
| 41 |
.gradio-container { max-width: 1200px !important; margin: 0 auto !important; padding: 2rem !important; }
|
| 42 |
|
| 43 |
-
/* Force teal on primary buttons */
|
| 44 |
-
button.primary,
|
| 45 |
-
.primary-btn {
|
| 46 |
-
background: linear-gradient(135deg, #0D9488, #0c0d0d) !important;
|
| 47 |
-
border: none !important;
|
| 48 |
-
color: white !important;
|
| 49 |
-
}
|
| 50 |
-
|
| 51 |
-
/* Header */
|
| 52 |
.app-header {
|
| 53 |
background: linear-gradient(135deg, #0D9488, #14B8A6);
|
| 54 |
border-radius: var(--radius);
|
|
@@ -59,61 +46,39 @@ button.primary,
|
|
| 59 |
box-shadow: var(--shadow);
|
| 60 |
}
|
| 61 |
|
| 62 |
-
/* Tabs */
|
| 63 |
.tab-nav { background: white !important; border-radius: var(--radius) !important; padding: 6px !important; border: 1px solid var(--border) !important; box-shadow: var(--shadow) !important; gap: 4px !important; }
|
| 64 |
.tab-nav button { border-radius: var(--radius-sm) !important; border: none !important; color: var(--text-muted) !important; font-weight: 500 !important; padding: 10px 20px !important; transition: all 0.2s !important; }
|
| 65 |
-
.tab-nav button.selected { background: linear-gradient(135deg, #
|
| 66 |
|
| 67 |
-
/* Cards */
|
| 68 |
.feature-card { background: white !important; border-radius: var(--radius) !important; border: 1px solid var(--border) !important; padding: 1.5rem !important; box-shadow: var(--shadow) !important; }
|
| 69 |
|
| 70 |
-
/* Inputs */
|
| 71 |
textarea, input[type=text], input[type=number] { border-radius: var(--radius-sm) !important; border: 1.5px solid var(--border) !important; background: var(--surface-2) !important; font-size: 14px !important; transition: border-color 0.2s !important; }
|
| 72 |
-
textarea:focus, input:focus { border-color: var(--primary) !important; box-shadow: 0 0 0 3px rgba(
|
| 73 |
|
| 74 |
-
|
| 75 |
-
|
| 76 |
-
|
| 77 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 78 |
|
| 79 |
-
|
| 80 |
.wrap { border-radius: var(--radius-sm) !important; border: 1.5px solid var(--border) !important; background: var(--surface-2) !important; }
|
| 81 |
-
|
| 82 |
-
/* Labels */
|
| 83 |
-
label span { font-weight: 600 !important; color: var(--text) !important; font-size: 13px !important; letter-spacing: 0.3px !important; }
|
| 84 |
-
|
| 85 |
-
/* Chat */
|
| 86 |
.chatbot { border-radius: var(--radius) !important; border: 1px solid var(--border) !important; box-shadow: var(--shadow) !important; }
|
| 87 |
-
.message.user { background: linear-gradient(135deg, #6C5CE7, #a29bfe) !important; color: white !important; border-radius: 18px 18px 4px 18px !important; }
|
| 88 |
-
.message.bot { background: white !important; border: 1px solid var(--border) !important; border-radius: 18px 18px 18px 4px !important; }
|
| 89 |
-
|
| 90 |
-
/* Section headers */
|
| 91 |
.section-title { font-size: 22px !important; font-weight: 700 !important; color: var(--text) !important; margin-bottom: 4px !important; }
|
| 92 |
.section-subtitle { font-size: 14px !important; color: var(--text-muted) !important; margin-bottom: 1.5rem !important; }
|
| 93 |
-
|
| 94 |
-
/* Stat badges */
|
| 95 |
-
.badge { display: inline-block; background: var(--surface-2); border: 1px solid var(--border); border-radius: 20px; padding: 4px 14px; font-size: 12px; color: var(--primary); font-weight: 600; margin: 4px; }
|
| 96 |
-
|
| 97 |
-
/* File upload */
|
| 98 |
.upload-btn { border-radius: var(--radius-sm) !important; border: 2px dashed var(--primary-light) !important; background: var(--surface-2) !important; }
|
| 99 |
-
|
| 100 |
-
/* Slider */
|
| 101 |
input[type=range] { accent-color: var(--primary) !important; }
|
| 102 |
-
|
| 103 |
-
/* Output boxes */
|
| 104 |
.output-box { background: var(--surface-2) !important; border: 1.5px solid var(--border) !important; border-radius: var(--radius-sm) !important; }
|
| 105 |
"""
|
| 106 |
|
|
|
|
| 107 |
def create_app():
|
| 108 |
-
with gr.Blocks(title="GenAI Toolkit",
|
| 109 |
-
|
| 110 |
-
css=custom_css,
|
| 111 |
-
theme=gr.themes.Base(
|
| 112 |
-
primary_hue=gr.themes.colors.blue,
|
| 113 |
-
neutral_hue=gr.themes.colors.slate,
|
| 114 |
-
font=[gr.themes.GoogleFont("Inter"), "sans-serif"]
|
| 115 |
-
)
|
| 116 |
-
) as app:
|
| 117 |
|
| 118 |
gr.HTML("""
|
| 119 |
<div class="app-header">
|
|
@@ -133,7 +98,7 @@ def create_app():
|
|
| 133 |
|
| 134 |
with gr.Tabs(elem_classes="tab-nav"):
|
| 135 |
|
| 136 |
-
#
|
| 137 |
with gr.Tab("π Translation"):
|
| 138 |
gr.HTML('<p class="section-title">Language Translation</p><p class="section-subtitle">Translate text instantly across 20+ languages using LLaMA 3</p>')
|
| 139 |
with gr.Row(equal_height=True):
|
|
@@ -142,40 +107,39 @@ def create_app():
|
|
| 142 |
with gr.Row():
|
| 143 |
t_src = gr.Dropdown(label="From", choices=LANGUAGES, value="English")
|
| 144 |
t_tgt = gr.Dropdown(label="To", choices=LANGUAGES, value="French")
|
| 145 |
-
t_btn = gr.Button("Translate β", variant="primary"
|
| 146 |
with gr.Column(scale=1, elem_classes="feature-card"):
|
| 147 |
t_out = gr.Textbox(label="Translation", lines=8, interactive=False, elem_classes="output-box")
|
| 148 |
-
gr.HTML('<p style="font-size:12px;color:#
|
| 149 |
t_btn.click(fn=translate_text, inputs=[t_input, t_src, t_tgt], outputs=t_out)
|
| 150 |
|
| 151 |
-
#
|
| 152 |
with gr.Tab("π Summarize"):
|
| 153 |
gr.HTML('<p class="section-title">Text Summarization</p><p class="section-subtitle">Condense long articles, reports, and documents into clear summaries</p>')
|
| 154 |
with gr.Row(equal_height=True):
|
| 155 |
with gr.Column(scale=1, elem_classes="feature-card"):
|
| 156 |
s_input = gr.Textbox(label="Text to Summarize", placeholder="Paste your article, report, or any long text here...", lines=12)
|
| 157 |
-
|
| 158 |
-
|
| 159 |
-
s_btn = gr.Button("Summarize β¦", variant="primary", elem_classes="primary-btn")
|
| 160 |
with gr.Column(scale=1, elem_classes="feature-card"):
|
| 161 |
s_out = gr.Textbox(label="Summary", lines=12, interactive=False, elem_classes="output-box")
|
| 162 |
-
gr.HTML('<p style="font-size:12px;color:#
|
| 163 |
s_btn.click(fn=summarize_text, inputs=[s_input, s_mode], outputs=s_out)
|
| 164 |
|
| 165 |
-
#
|
| 166 |
with gr.Tab("π Keywords"):
|
| 167 |
gr.HTML('<p class="section-title">Keyword Extraction</p><p class="section-subtitle">Identify the most important topics and phrases in any text</p>')
|
| 168 |
with gr.Row(equal_height=True):
|
| 169 |
with gr.Column(scale=1, elem_classes="feature-card"):
|
| 170 |
k_input = gr.Textbox(label="Input Text", placeholder="Paste any text to extract key topics...", lines=10)
|
| 171 |
k_num = gr.Slider(label="Number of Keywords", minimum=5, maximum=20, value=10, step=1)
|
| 172 |
-
k_btn = gr.Button("Extract Keywords π", variant="primary"
|
| 173 |
with gr.Column(scale=1, elem_classes="feature-card"):
|
| 174 |
k_out = gr.Textbox(label="Extracted Keywords", lines=10, interactive=False, elem_classes="output-box")
|
| 175 |
-
gr.HTML('<p style="font-size:12px;color:#
|
| 176 |
k_btn.click(fn=extract_keywords, inputs=[k_input, k_num], outputs=k_out)
|
| 177 |
|
| 178 |
-
#
|
| 179 |
with gr.Tab("βοΈ Email Writer"):
|
| 180 |
gr.HTML('<p class="section-title">Email & Cover Letter Writer</p><p class="section-subtitle">Generate professional emails and cover letters instantly</p>')
|
| 181 |
with gr.Tabs():
|
|
@@ -188,7 +152,7 @@ def create_app():
|
|
| 188 |
with gr.Row():
|
| 189 |
e_to = gr.Textbox(label="Recipient", placeholder="Hiring Manager")
|
| 190 |
e_from = gr.Textbox(label="Your Name", placeholder="Shashank")
|
| 191 |
-
e_btn = gr.Button("Generate Email βοΈ", variant="primary"
|
| 192 |
with gr.Column(scale=1, elem_classes="feature-card"):
|
| 193 |
e_out = gr.Textbox(label="Generated Email", lines=18, interactive=False, elem_classes="output-box")
|
| 194 |
e_btn.click(fn=write_email, inputs=[e_type, e_ctx, e_tone, e_to, e_from], outputs=e_out)
|
|
@@ -201,29 +165,29 @@ def create_app():
|
|
| 201 |
cl_co = gr.Textbox(label="Company Name", placeholder="Google DeepMind")
|
| 202 |
cl_sk = gr.Textbox(label="Key Skills", placeholder="Python, LangChain, MLflow, XGBoost...", lines=3)
|
| 203 |
cl_exp = gr.Textbox(label="Experience Summary", placeholder="3 years building ML pipelines...", lines=3)
|
| 204 |
-
cl_btn = gr.Button("Generate Cover Letter π", variant="primary"
|
| 205 |
with gr.Column(scale=1, elem_classes="feature-card"):
|
| 206 |
cl_out = gr.Textbox(label="Cover Letter", lines=18, interactive=False, elem_classes="output-box")
|
| 207 |
cl_btn.click(fn=write_cover_letter, inputs=[cl_job, cl_co, cl_sk, cl_exp, cl_name], outputs=cl_out)
|
| 208 |
|
| 209 |
-
#
|
| 210 |
with gr.Tab("π¬ Chat"):
|
| 211 |
gr.HTML('<p class="section-title">AI Chat Assistant</p><p class="section-subtitle">Multi-turn conversations powered by LangGraph + LLaMA 3.3 70B</p>')
|
| 212 |
with gr.Column(elem_classes="feature-card"):
|
| 213 |
-
chatbot = gr.Chatbot(height=450, label="", elem_classes="chatbot", show_label=False
|
| 214 |
with gr.Row():
|
| 215 |
c_input = gr.Textbox(label="", placeholder="Ask me anything...", scale=5, container=False)
|
| 216 |
-
c_btn = gr.Button("Send β", variant="primary", scale=1
|
| 217 |
with gr.Row():
|
| 218 |
c_clear = gr.Button("ποΈ Clear Conversation", elem_classes="secondary-btn")
|
| 219 |
-
gr.HTML('<p style="font-size:12px;color:#
|
| 220 |
|
| 221 |
def respond(message, history):
|
| 222 |
if not message.strip():
|
| 223 |
return "", history
|
| 224 |
response = chat_session.chat(message)
|
| 225 |
-
history
|
| 226 |
-
history.append(
|
| 227 |
return "", history
|
| 228 |
|
| 229 |
def clear():
|
|
@@ -234,7 +198,7 @@ def create_app():
|
|
| 234 |
c_input.submit(fn=respond, inputs=[c_input, chatbot], outputs=[c_input, chatbot])
|
| 235 |
c_clear.click(fn=clear, outputs=chatbot)
|
| 236 |
|
| 237 |
-
#
|
| 238 |
with gr.Tab("π PDF Q&A"):
|
| 239 |
gr.HTML('<p class="section-title">PDF Question & Answer</p><p class="section-subtitle">Upload any PDF and ask questions β powered by RAG + LangGraph</p>')
|
| 240 |
pdf_state = gr.State("")
|
|
@@ -243,8 +207,8 @@ def create_app():
|
|
| 243 |
p_file = gr.File(label="Upload PDF", file_types=[".pdf"], elem_classes="upload-btn")
|
| 244 |
p_status = gr.Textbox(label="Status", interactive=False, lines=1)
|
| 245 |
p_q = gr.Textbox(label="Your Question", placeholder="What is the main topic of this document?", lines=4)
|
| 246 |
-
p_btn = gr.Button("Ask Question π", variant="primary"
|
| 247 |
-
gr.HTML('<p style="font-size:12px;color:#
|
| 248 |
with gr.Column(scale=1, elem_classes="feature-card"):
|
| 249 |
p_out = gr.Textbox(label="Answer", lines=18, interactive=False, elem_classes="output-box")
|
| 250 |
|
|
@@ -261,25 +225,31 @@ def create_app():
|
|
| 261 |
if not question.strip():
|
| 262 |
return "β οΈ Please enter a question."
|
| 263 |
graph = build_pdf_qa_graph()
|
| 264 |
-
result = graph.invoke({
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 265 |
return result["answer"]
|
| 266 |
|
| 267 |
p_file.change(fn=load_pdf_file, inputs=p_file, outputs=[pdf_state, p_status])
|
| 268 |
p_btn.click(fn=answer_pdf_question, inputs=[p_q, pdf_state], outputs=p_out)
|
| 269 |
|
| 270 |
gr.HTML("""
|
| 271 |
-
<div style="text-align:center;padding:2rem;color:#
|
| 272 |
-
Built with LangChain Β· LangGraph Β· Groq Β· Gradio |
|
| 273 |
-
<a href="https://github.com/shashankheg" style="color:#
|
| 274 |
</div>
|
| 275 |
""")
|
| 276 |
|
| 277 |
return app
|
| 278 |
|
|
|
|
| 279 |
if __name__ == "__main__":
|
| 280 |
app = create_app()
|
| 281 |
app.launch(
|
| 282 |
-
|
| 283 |
-
|
| 284 |
-
|
| 285 |
-
)
|
|
|
|
|
|
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
from src.features.translation import translate_text
|
| 3 |
from src.features.summarization import summarize_text
|
| 4 |
from src.features.keyword_extraction import extract_keywords
|
| 5 |
from src.features.email_writer import write_email, write_cover_letter
|
| 6 |
+
from src.features.pdf_qa import load_pdf, build_pdf_qa_graph
|
| 7 |
from src.graphs.chat_graph import ChatSession
|
| 8 |
|
| 9 |
chat_session = ChatSession()
|
|
|
|
| 17 |
|
| 18 |
custom_css = """
|
| 19 |
:root {
|
| 20 |
+
--primary: #0D9488;
|
| 21 |
+
--primary-light: #5EEAD4;
|
| 22 |
--surface: #ffffff;
|
| 23 |
+
--surface-2: #f0fdfa;
|
| 24 |
+
--border: #ccfbf1;
|
| 25 |
+
--text: #134e4a;
|
| 26 |
+
--text-muted: #6b7280;
|
|
|
|
| 27 |
--radius: 16px;
|
| 28 |
--radius-sm: 10px;
|
| 29 |
+
--shadow: 0 4px 24px rgba(13,148,136,0.10);
|
|
|
|
| 30 |
}
|
| 31 |
|
| 32 |
body, .gradio-container {
|
| 33 |
+
background: linear-gradient(135deg, #f0fdfa 0%, #e6fffa 100%) !important;
|
| 34 |
font-family: 'Inter', 'Segoe UI', sans-serif !important;
|
| 35 |
}
|
| 36 |
|
| 37 |
.gradio-container { max-width: 1200px !important; margin: 0 auto !important; padding: 2rem !important; }
|
| 38 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 39 |
.app-header {
|
| 40 |
background: linear-gradient(135deg, #0D9488, #14B8A6);
|
| 41 |
border-radius: var(--radius);
|
|
|
|
| 46 |
box-shadow: var(--shadow);
|
| 47 |
}
|
| 48 |
|
|
|
|
| 49 |
.tab-nav { background: white !important; border-radius: var(--radius) !important; padding: 6px !important; border: 1px solid var(--border) !important; box-shadow: var(--shadow) !important; gap: 4px !important; }
|
| 50 |
.tab-nav button { border-radius: var(--radius-sm) !important; border: none !important; color: var(--text-muted) !important; font-weight: 500 !important; padding: 10px 20px !important; transition: all 0.2s !important; }
|
| 51 |
+
.tab-nav button.selected { background: linear-gradient(135deg, #0D9488, #14B8A6) !important; color: white !important; box-shadow: 0 4px 12px rgba(13,148,136,0.3) !important; }
|
| 52 |
|
|
|
|
| 53 |
.feature-card { background: white !important; border-radius: var(--radius) !important; border: 1px solid var(--border) !important; padding: 1.5rem !important; box-shadow: var(--shadow) !important; }
|
| 54 |
|
|
|
|
| 55 |
textarea, input[type=text], input[type=number] { border-radius: var(--radius-sm) !important; border: 1.5px solid var(--border) !important; background: var(--surface-2) !important; font-size: 14px !important; transition: border-color 0.2s !important; }
|
| 56 |
+
textarea:focus, input:focus { border-color: var(--primary) !important; box-shadow: 0 0 0 3px rgba(13,148,136,0.15) !important; }
|
| 57 |
|
| 58 |
+
button.primary, .gr-button-primary {
|
| 59 |
+
background: linear-gradient(135deg, #0D9488, #14B8A6) !important;
|
| 60 |
+
border: none !important;
|
| 61 |
+
color: white !important;
|
| 62 |
+
font-weight: 600 !important;
|
| 63 |
+
border-radius: var(--radius-sm) !important;
|
| 64 |
+
box-shadow: 0 4px 12px rgba(13,148,136,0.3) !important;
|
| 65 |
+
}
|
| 66 |
|
| 67 |
+
.secondary-btn { background: white !important; border: 1.5px solid var(--border) !important; border-radius: var(--radius-sm) !important; color: var(--primary) !important; font-weight: 500 !important; }
|
| 68 |
.wrap { border-radius: var(--radius-sm) !important; border: 1.5px solid var(--border) !important; background: var(--surface-2) !important; }
|
| 69 |
+
label span { font-weight: 600 !important; color: var(--text) !important; font-size: 13px !important; }
|
|
|
|
|
|
|
|
|
|
|
|
|
| 70 |
.chatbot { border-radius: var(--radius) !important; border: 1px solid var(--border) !important; box-shadow: var(--shadow) !important; }
|
|
|
|
|
|
|
|
|
|
|
|
|
| 71 |
.section-title { font-size: 22px !important; font-weight: 700 !important; color: var(--text) !important; margin-bottom: 4px !important; }
|
| 72 |
.section-subtitle { font-size: 14px !important; color: var(--text-muted) !important; margin-bottom: 1.5rem !important; }
|
| 73 |
+
.badge { display: inline-block; background: rgba(255,255,255,0.2); border: 1px solid rgba(255,255,255,0.4); border-radius: 20px; padding: 4px 14px; font-size: 12px; color: white; font-weight: 600; margin: 4px; }
|
|
|
|
|
|
|
|
|
|
|
|
|
| 74 |
.upload-btn { border-radius: var(--radius-sm) !important; border: 2px dashed var(--primary-light) !important; background: var(--surface-2) !important; }
|
|
|
|
|
|
|
| 75 |
input[type=range] { accent-color: var(--primary) !important; }
|
|
|
|
|
|
|
| 76 |
.output-box { background: var(--surface-2) !important; border: 1.5px solid var(--border) !important; border-radius: var(--radius-sm) !important; }
|
| 77 |
"""
|
| 78 |
|
| 79 |
+
|
| 80 |
def create_app():
|
| 81 |
+
with gr.Blocks(title="GenAI Toolkit", css=custom_css) as app:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 82 |
|
| 83 |
gr.HTML("""
|
| 84 |
<div class="app-header">
|
|
|
|
| 98 |
|
| 99 |
with gr.Tabs(elem_classes="tab-nav"):
|
| 100 |
|
| 101 |
+
# TRANSLATION
|
| 102 |
with gr.Tab("π Translation"):
|
| 103 |
gr.HTML('<p class="section-title">Language Translation</p><p class="section-subtitle">Translate text instantly across 20+ languages using LLaMA 3</p>')
|
| 104 |
with gr.Row(equal_height=True):
|
|
|
|
| 107 |
with gr.Row():
|
| 108 |
t_src = gr.Dropdown(label="From", choices=LANGUAGES, value="English")
|
| 109 |
t_tgt = gr.Dropdown(label="To", choices=LANGUAGES, value="French")
|
| 110 |
+
t_btn = gr.Button("Translate β", variant="primary")
|
| 111 |
with gr.Column(scale=1, elem_classes="feature-card"):
|
| 112 |
t_out = gr.Textbox(label="Translation", lines=8, interactive=False, elem_classes="output-box")
|
| 113 |
+
gr.HTML('<p style="font-size:12px;color:#6b7280;margin-top:8px">β‘ Powered by LLaMA 3.1 Β· Fast & accurate</p>')
|
| 114 |
t_btn.click(fn=translate_text, inputs=[t_input, t_src, t_tgt], outputs=t_out)
|
| 115 |
|
| 116 |
+
# SUMMARIZATION
|
| 117 |
with gr.Tab("π Summarize"):
|
| 118 |
gr.HTML('<p class="section-title">Text Summarization</p><p class="section-subtitle">Condense long articles, reports, and documents into clear summaries</p>')
|
| 119 |
with gr.Row(equal_height=True):
|
| 120 |
with gr.Column(scale=1, elem_classes="feature-card"):
|
| 121 |
s_input = gr.Textbox(label="Text to Summarize", placeholder="Paste your article, report, or any long text here...", lines=12)
|
| 122 |
+
s_mode = gr.Radio(label="Summary Style", choices=["concise", "detailed"], value="concise")
|
| 123 |
+
s_btn = gr.Button("Summarize β¦", variant="primary")
|
|
|
|
| 124 |
with gr.Column(scale=1, elem_classes="feature-card"):
|
| 125 |
s_out = gr.Textbox(label="Summary", lines=12, interactive=False, elem_classes="output-box")
|
| 126 |
+
gr.HTML('<p style="font-size:12px;color:#6b7280;margin-top:8px">π Supports long documents via map-reduce chunking</p>')
|
| 127 |
s_btn.click(fn=summarize_text, inputs=[s_input, s_mode], outputs=s_out)
|
| 128 |
|
| 129 |
+
# KEYWORDS
|
| 130 |
with gr.Tab("π Keywords"):
|
| 131 |
gr.HTML('<p class="section-title">Keyword Extraction</p><p class="section-subtitle">Identify the most important topics and phrases in any text</p>')
|
| 132 |
with gr.Row(equal_height=True):
|
| 133 |
with gr.Column(scale=1, elem_classes="feature-card"):
|
| 134 |
k_input = gr.Textbox(label="Input Text", placeholder="Paste any text to extract key topics...", lines=10)
|
| 135 |
k_num = gr.Slider(label="Number of Keywords", minimum=5, maximum=20, value=10, step=1)
|
| 136 |
+
k_btn = gr.Button("Extract Keywords π", variant="primary")
|
| 137 |
with gr.Column(scale=1, elem_classes="feature-card"):
|
| 138 |
k_out = gr.Textbox(label="Extracted Keywords", lines=10, interactive=False, elem_classes="output-box")
|
| 139 |
+
gr.HTML('<p style="font-size:12px;color:#6b7280;margin-top:8px">π·οΈ Returns keywords with context and relevance</p>')
|
| 140 |
k_btn.click(fn=extract_keywords, inputs=[k_input, k_num], outputs=k_out)
|
| 141 |
|
| 142 |
+
# EMAIL WRITER
|
| 143 |
with gr.Tab("βοΈ Email Writer"):
|
| 144 |
gr.HTML('<p class="section-title">Email & Cover Letter Writer</p><p class="section-subtitle">Generate professional emails and cover letters instantly</p>')
|
| 145 |
with gr.Tabs():
|
|
|
|
| 152 |
with gr.Row():
|
| 153 |
e_to = gr.Textbox(label="Recipient", placeholder="Hiring Manager")
|
| 154 |
e_from = gr.Textbox(label="Your Name", placeholder="Shashank")
|
| 155 |
+
e_btn = gr.Button("Generate Email βοΈ", variant="primary")
|
| 156 |
with gr.Column(scale=1, elem_classes="feature-card"):
|
| 157 |
e_out = gr.Textbox(label="Generated Email", lines=18, interactive=False, elem_classes="output-box")
|
| 158 |
e_btn.click(fn=write_email, inputs=[e_type, e_ctx, e_tone, e_to, e_from], outputs=e_out)
|
|
|
|
| 165 |
cl_co = gr.Textbox(label="Company Name", placeholder="Google DeepMind")
|
| 166 |
cl_sk = gr.Textbox(label="Key Skills", placeholder="Python, LangChain, MLflow, XGBoost...", lines=3)
|
| 167 |
cl_exp = gr.Textbox(label="Experience Summary", placeholder="3 years building ML pipelines...", lines=3)
|
| 168 |
+
cl_btn = gr.Button("Generate Cover Letter π", variant="primary")
|
| 169 |
with gr.Column(scale=1, elem_classes="feature-card"):
|
| 170 |
cl_out = gr.Textbox(label="Cover Letter", lines=18, interactive=False, elem_classes="output-box")
|
| 171 |
cl_btn.click(fn=write_cover_letter, inputs=[cl_job, cl_co, cl_sk, cl_exp, cl_name], outputs=cl_out)
|
| 172 |
|
| 173 |
+
# CHAT
|
| 174 |
with gr.Tab("π¬ Chat"):
|
| 175 |
gr.HTML('<p class="section-title">AI Chat Assistant</p><p class="section-subtitle">Multi-turn conversations powered by LangGraph + LLaMA 3.3 70B</p>')
|
| 176 |
with gr.Column(elem_classes="feature-card"):
|
| 177 |
+
chatbot = gr.Chatbot(height=450, label="", elem_classes="chatbot", show_label=False)
|
| 178 |
with gr.Row():
|
| 179 |
c_input = gr.Textbox(label="", placeholder="Ask me anything...", scale=5, container=False)
|
| 180 |
+
c_btn = gr.Button("Send β", variant="primary", scale=1)
|
| 181 |
with gr.Row():
|
| 182 |
c_clear = gr.Button("ποΈ Clear Conversation", elem_classes="secondary-btn")
|
| 183 |
+
gr.HTML('<p style="font-size:12px;color:#6b7280;padding-top:10px">π§ Maintains full conversation context via LangGraph state</p>')
|
| 184 |
|
| 185 |
def respond(message, history):
|
| 186 |
if not message.strip():
|
| 187 |
return "", history
|
| 188 |
response = chat_session.chat(message)
|
| 189 |
+
history = history or []
|
| 190 |
+
history.append((message, response))
|
| 191 |
return "", history
|
| 192 |
|
| 193 |
def clear():
|
|
|
|
| 198 |
c_input.submit(fn=respond, inputs=[c_input, chatbot], outputs=[c_input, chatbot])
|
| 199 |
c_clear.click(fn=clear, outputs=chatbot)
|
| 200 |
|
| 201 |
+
# PDF Q&A
|
| 202 |
with gr.Tab("π PDF Q&A"):
|
| 203 |
gr.HTML('<p class="section-title">PDF Question & Answer</p><p class="section-subtitle">Upload any PDF and ask questions β powered by RAG + LangGraph</p>')
|
| 204 |
pdf_state = gr.State("")
|
|
|
|
| 207 |
p_file = gr.File(label="Upload PDF", file_types=[".pdf"], elem_classes="upload-btn")
|
| 208 |
p_status = gr.Textbox(label="Status", interactive=False, lines=1)
|
| 209 |
p_q = gr.Textbox(label="Your Question", placeholder="What is the main topic of this document?", lines=4)
|
| 210 |
+
p_btn = gr.Button("Ask Question π", variant="primary")
|
| 211 |
+
gr.HTML('<p style="font-size:12px;color:#6b7280;margin-top:8px">π Uses FAISS vector search + semantic chunking</p>')
|
| 212 |
with gr.Column(scale=1, elem_classes="feature-card"):
|
| 213 |
p_out = gr.Textbox(label="Answer", lines=18, interactive=False, elem_classes="output-box")
|
| 214 |
|
|
|
|
| 225 |
if not question.strip():
|
| 226 |
return "β οΈ Please enter a question."
|
| 227 |
graph = build_pdf_qa_graph()
|
| 228 |
+
result = graph.invoke({
|
| 229 |
+
"pdf_text": pdf_text,
|
| 230 |
+
"question": question,
|
| 231 |
+
"context": "",
|
| 232 |
+
"answer": ""
|
| 233 |
+
})
|
| 234 |
return result["answer"]
|
| 235 |
|
| 236 |
p_file.change(fn=load_pdf_file, inputs=p_file, outputs=[pdf_state, p_status])
|
| 237 |
p_btn.click(fn=answer_pdf_question, inputs=[p_q, pdf_state], outputs=p_out)
|
| 238 |
|
| 239 |
gr.HTML("""
|
| 240 |
+
<div style="text-align:center;padding:2rem;color:#6b7280;font-size:13px;margin-top:1rem">
|
| 241 |
+
Built with LangChain Β· LangGraph Β· Groq Β· Gradio |
|
| 242 |
+
<a href="https://github.com/shashankheg" style="color:#0D9488;text-decoration:none">GitHub</a>
|
| 243 |
</div>
|
| 244 |
""")
|
| 245 |
|
| 246 |
return app
|
| 247 |
|
| 248 |
+
|
| 249 |
if __name__ == "__main__":
|
| 250 |
app = create_app()
|
| 251 |
app.launch(
|
| 252 |
+
server_name="0.0.0.0",
|
| 253 |
+
server_port=7860,
|
| 254 |
+
share=False
|
| 255 |
+
)
|