GermanySutherland/Agentic-AI-NLP-LLM
0
1import gradio as gr2from transformers import pipeline3 4# Load a free Hugging Face model (small + free to run)5generator = pipeline("text2text-generation", model="google/flan-t5-small")6 7# Agent function8def agentic_ai(user_input):9 # Step 1: Analyze input10 analysis_prompt = f"Analyze the intent of this input: {user_input}"11 analysis = generator(analysis_prompt, max_length=50, do_sample=False)[0]['generated_text']12 13 # Step 2: Decide what to do (simple rule-based agent)14 if "summarize" in user_input.lower():15 task_prompt = f"Summarize this text in 2 lines: {user_input}"16 elif "question" in user_input.lower() or "?" in user_input:17 task_prompt = f"Answer this question briefly: {user_input}"18 else:19 task_prompt = f"Generate a helpful response: {user_input}"20 21 # Step 3: LLM Response22 response = generator(task_prompt, max_length=80, do_sample=False)[0]['generated_text']23 24 # Step 4: Return both analysis + final response25 return f"๐ Agent Analysis: {analysis}\n\n๐ก Agent Response: {response}"26 27 28# Gradio UI29demo = gr.Interface(30 fn=agentic_ai,31 inputs=gr.Textbox(lines=3, placeholder="Type your text here..."),32 outputs="text",33 title="๐ค Mini Agentic LLM App",34 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"35)36 37if __name__ == "__main__":38 demo.launch()39 