Upload folder using huggingface_hub
Browse files- README.md +1 -1
- agent.py +60 -0
- requirements.txt +0 -1
README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
| 1 |
---
|
| 2 |
title: content
|
| 3 |
-
app_file:
|
| 4 |
sdk: gradio
|
| 5 |
sdk_version: 5.42.0
|
| 6 |
---
|
|
|
|
| 1 |
---
|
| 2 |
title: content
|
| 3 |
+
app_file: agent.py
|
| 4 |
sdk: gradio
|
| 5 |
sdk_version: 5.42.0
|
| 6 |
---
|
agent.py
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
|
| 3 |
+
# -------- Agent بسيط --------
|
| 4 |
+
class SimpleAgent:
|
| 5 |
+
def __init__(self, name):
|
| 6 |
+
self.name = name
|
| 7 |
+
self.intents = {}
|
| 8 |
+
|
| 9 |
+
def add_intent(self, intent_name, examples, response):
|
| 10 |
+
self.intents[intent_name] = {
|
| 11 |
+
"examples": examples,
|
| 12 |
+
"response": response
|
| 13 |
+
}
|
| 14 |
+
|
| 15 |
+
def chat(self, user_input):
|
| 16 |
+
for intent, data in self.intents.items():
|
| 17 |
+
for ex in data["examples"]:
|
| 18 |
+
if ex.lower() in user_input.lower():
|
| 19 |
+
return data["response"]
|
| 20 |
+
return "🤔 Sorry, I didn’t understand. Can you rephrase?"
|
| 21 |
+
|
| 22 |
+
# -------- تعريف Agent --------
|
| 23 |
+
agent = SimpleAgent("SupportAgent")
|
| 24 |
+
|
| 25 |
+
agent.add_intent(
|
| 26 |
+
"greeting",
|
| 27 |
+
["hello", "hi", "hey"],
|
| 28 |
+
"👋 Hello! How can I help you today?"
|
| 29 |
+
)
|
| 30 |
+
|
| 31 |
+
agent.add_intent(
|
| 32 |
+
"order_status",
|
| 33 |
+
["track my order", "order status", "where is my package"],
|
| 34 |
+
"📦 Sure! Please provide your order ID."
|
| 35 |
+
)
|
| 36 |
+
|
| 37 |
+
agent.add_intent(
|
| 38 |
+
"goodbye",
|
| 39 |
+
["bye", "goodbye", "see you"],
|
| 40 |
+
"👋 Goodbye! Have a great day 🌟"
|
| 41 |
+
)
|
| 42 |
+
|
| 43 |
+
# -------- Gradio واجهة --------
|
| 44 |
+
def chat_with_agent(user_input, history):
|
| 45 |
+
response = agent.chat(user_input)
|
| 46 |
+
history.append((user_input, response))
|
| 47 |
+
return history, history
|
| 48 |
+
|
| 49 |
+
with gr.Blocks() as demo:
|
| 50 |
+
gr.Markdown("## 🤖 Simple AI Agent (Google Agent Builder - Lab Simulation)")
|
| 51 |
+
chatbot = gr.Chatbot()
|
| 52 |
+
msg = gr.Textbox(placeholder="Type your message here...")
|
| 53 |
+
clear = gr.Button("Clear")
|
| 54 |
+
|
| 55 |
+
state = gr.State([])
|
| 56 |
+
|
| 57 |
+
msg.submit(chat_with_agent, [msg, state], [chatbot, state])
|
| 58 |
+
clear.click(lambda: ([], []), None, [chatbot, state])
|
| 59 |
+
|
| 60 |
+
demo.launch()
|
requirements.txt
CHANGED
|
@@ -1,2 +1 @@
|
|
| 1 |
gradio
|
| 2 |
-
google-generativeai
|
|
|
|
| 1 |
gradio
|
|
|