Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,63 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
from transformers import pipeline
|
| 3 |
+
|
| 4 |
+
# Load small + free LLM
|
| 5 |
+
generator = pipeline("text2text-generation", model="google/flan-t5-small")
|
| 6 |
+
|
| 7 |
+
# --- Agent 1: Summarizer + Knowledge Graph Builder ---
|
| 8 |
+
def doc_agent(user_text):
|
| 9 |
+
# Step 1: Summarize
|
| 10 |
+
summary_prompt = f"Summarize this in 3 lines: {user_text}"
|
| 11 |
+
summary = generator(summary_prompt, max_length=80, do_sample=False)[0]['generated_text']
|
| 12 |
+
|
| 13 |
+
# Step 2: Build a "mini knowledge graph" (keywords as nodes)
|
| 14 |
+
keyword_prompt = f"Extract 5 important keywords from this text: {user_text}"
|
| 15 |
+
keywords = generator(keyword_prompt, max_length=40, do_sample=False)[0]['generated_text']
|
| 16 |
+
graph_nodes = [kw.strip() for kw in keywords.split(",") if kw.strip()]
|
| 17 |
+
graph_repr = " β ".join(graph_nodes) if graph_nodes else "No graph generated."
|
| 18 |
+
|
| 19 |
+
return f"π Summary:\n{summary}\n\nπΈοΈ Knowledge Graph:\n{graph_repr}"
|
| 20 |
+
|
| 21 |
+
# --- Agent 2: Career Skill Recommender ---
|
| 22 |
+
def career_agent(user_goal):
|
| 23 |
+
# Step 1: Analyze career intent
|
| 24 |
+
analysis_prompt = f"Identify skill gap for this career goal: {user_goal}"
|
| 25 |
+
analysis = generator(analysis_prompt, max_length=50, do_sample=False)[0]['generated_text']
|
| 26 |
+
|
| 27 |
+
# Step 2: Recommend roadmap
|
| 28 |
+
roadmap_prompt = f"Suggest a 3-step learning roadmap for: {user_goal}"
|
| 29 |
+
roadmap = generator(roadmap_prompt, max_length=80, do_sample=False)[0]['generated_text']
|
| 30 |
+
|
| 31 |
+
return f"π Gap Analysis:\n{analysis}\n\nπ οΈ Skill Roadmap:\n{roadmap}"
|
| 32 |
+
|
| 33 |
+
# --- Combined Agent Controller ---
|
| 34 |
+
def agentic_ai(user_input, mode):
|
| 35 |
+
if mode == "Document Insight":
|
| 36 |
+
return doc_agent(user_input)
|
| 37 |
+
elif mode == "Career Roadmap":
|
| 38 |
+
return career_agent(user_input)
|
| 39 |
+
else:
|
| 40 |
+
return "β οΈ Please choose a valid mode."
|
| 41 |
+
|
| 42 |
+
# --- Demo UI ---
|
| 43 |
+
demo = gr.Interface(
|
| 44 |
+
fn=agentic_ai,
|
| 45 |
+
inputs=[
|
| 46 |
+
gr.Textbox(lines=4, placeholder="Enter text or career goal..."),
|
| 47 |
+
gr.Radio(["Document Insight", "Career Roadmap"], label="Choose Mode")
|
| 48 |
+
],
|
| 49 |
+
outputs="text",
|
| 50 |
+
title="π Mini Agentic AI MVP",
|
| 51 |
+
description="""
|
| 52 |
+
This smallest MVP demonstrates:
|
| 53 |
+
- π Document Summarization
|
| 54 |
+
- πΈοΈ Knowledge Graph (mini keyword graph)
|
| 55 |
+
- π§βπ» Career Skill Gap Analysis
|
| 56 |
+
- π οΈ Personalized 3-step Roadmap
|
| 57 |
+
|
| 58 |
+
Built with free Hugging Face + Gradio. Optimized for AI Research use cases.
|
| 59 |
+
"""
|
| 60 |
+
)
|
| 61 |
+
|
| 62 |
+
if __name__ == "__main__":
|
| 63 |
+
demo.launch()
|