|
|
import gradio as gr |
|
|
from transformers import pipeline |
|
|
|
|
|
|
|
|
generator = pipeline("text2text-generation", model="google/flan-t5-small") |
|
|
|
|
|
|
|
|
def agentic_ai(user_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'] |
|
|
|
|
|
|
|
|
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}" |
|
|
|
|
|
|
|
|
response = generator(task_prompt, max_length=80, do_sample=False)[0]['generated_text'] |
|
|
|
|
|
|
|
|
return f"π Agent Analysis: {analysis}\n\nπ‘ Agent Response: {response}" |
|
|
|
|
|
|
|
|
|
|
|
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() |
|
|
|