File size: 1,446 Bytes
9435cbe
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
e26d4af
9435cbe
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
import gradio as gr
from transformers import pipeline

# Load a free Hugging Face model (small + free to run)
generator = pipeline("text2text-generation", model="google/flan-t5-small")

# Agent function
def agentic_ai(user_input):
    # Step 1: Analyze input
    analysis_prompt = f"Analyze the intent of this input: {user_input}"
    analysis = generator(analysis_prompt, max_length=50, do_sample=False)[0]['generated_text']

    # Step 2: Decide what to do (simple rule-based agent)
    if "summarize" in user_input.lower():
        task_prompt = f"Summarize this text in 2 lines: {user_input}"
    elif "question" in user_input.lower() or "?" in user_input:
        task_prompt = f"Answer this question briefly: {user_input}"
    else:
        task_prompt = f"Generate a helpful response: {user_input}"

    # Step 3: LLM Response
    response = generator(task_prompt, max_length=80, do_sample=False)[0]['generated_text']

    # Step 4: Return both analysis + final response
    return f"🔎 Agent Analysis: {analysis}\n\n💡 Agent Response: {response}"


# Gradio UI
demo = gr.Interface(
    fn=agentic_ai,
    inputs=gr.Textbox(lines=3, placeholder="Type your text here..."),
    outputs="text",
    title="🤖 Mini Agentic LLM App",
    description="Smallest free demo of an Agentic AI using NLP + LLM on Hugging Face & Gradio. Input few lines or paragraph with question and Click Submit"
)

if __name__ == "__main__":
    demo.launch()