Spaces:
Runtime error
Runtime error
Upload 3 files
Browse files- README.md +36 -31
- app.py +25 -16
- requirements.txt +1 -3
README.md
CHANGED
|
@@ -1,43 +1,48 @@
|
|
| 1 |
-
|
| 2 |
-
|
| 3 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 4 |
|
| 5 |
-
|
| 6 |
|
| 7 |
-
|
| 8 |
-
2. مفتاح API من OpenAI
|
| 9 |
|
| 10 |
-
##
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 11 |
|
| 12 |
-
|
| 13 |
-
```bash
|
| 14 |
-
pip install -r requirements.txt
|
| 15 |
```
|
| 16 |
-
|
| 17 |
-
2.
|
| 18 |
-
|
| 19 |
-
|
| 20 |
```
|
| 21 |
|
| 22 |
-
##
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
python auto_responder.py
|
| 27 |
```
|
| 28 |
|
| 29 |
-
2.
|
| 30 |
-
```
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
responder = AutoResponder("your-api-key-here")
|
| 34 |
-
response = responder.generate_response("مرحبا!", "user123")
|
| 35 |
-
print(response)
|
| 36 |
```
|
| 37 |
|
| 38 |
-
##
|
|
|
|
|
|
|
|
|
|
|
|
|
| 39 |
|
| 40 |
-
|
| 41 |
-
- حفظ سجل المحادثات لكل مستخدم
|
| 42 |
-
- إمكانية مسح سجل المحادثات
|
| 43 |
-
- دعم اللغة العربية
|
|
|
|
| 1 |
+
---
|
| 2 |
+
title: Arabic AI Auto Responder
|
| 3 |
+
emoji: 💬
|
| 4 |
+
colorFrom: blue
|
| 5 |
+
colorTo: purple
|
| 6 |
+
sdk: gradio
|
| 7 |
+
sdk_version: "4.12.0"
|
| 8 |
+
app_file: app.py
|
| 9 |
+
pinned: false
|
| 10 |
+
---
|
| 11 |
|
| 12 |
+
# وكيل الرد التلقائي بالذكاء الاصطناعي
|
| 13 |
|
| 14 |
+
هذا المشروع عبارة عن وكيل ذكاء اصطناعي مفتوح المصدر يقوم بالرد تلقائياً على الرسائل باستخدام نموذج Blenderbot.
|
|
|
|
| 15 |
|
| 16 |
+
## المميزات
|
| 17 |
+
- نموذج مفتوح المصدر (facebook/blenderbot-400M-distill)
|
| 18 |
+
- واجهة محادثة تفاعلية باستخدام Gradio
|
| 19 |
+
- حفظ سجل المحادثات
|
| 20 |
+
- سهولة النشر على Hugging Face Spaces
|
| 21 |
+
- أمثلة جاهزة للاستخدام
|
| 22 |
|
| 23 |
+
## المتطلبات
|
|
|
|
|
|
|
| 24 |
```
|
| 25 |
+
transformers==4.36.2
|
| 26 |
+
torch==2.1.2
|
| 27 |
+
sentencepiece==0.1.99
|
| 28 |
+
gradio==4.12.0
|
| 29 |
```
|
| 30 |
|
| 31 |
+
## التشغيل المحلي
|
| 32 |
+
1. تثبيت المتطلبات:
|
| 33 |
+
```bash
|
| 34 |
+
pip install -r requirements.txt
|
|
|
|
| 35 |
```
|
| 36 |
|
| 37 |
+
2. تشغيل التطبيق:
|
| 38 |
+
```bash
|
| 39 |
+
python app.py
|
|
|
|
|
|
|
|
|
|
|
|
|
| 40 |
```
|
| 41 |
|
| 42 |
+
## الاستخدام
|
| 43 |
+
1. افتح المتصفح على العنوان المحلي (عادة http://localhost:7860)
|
| 44 |
+
2. اكتب رسالتك في مربع المحادثة
|
| 45 |
+
3. اضغط على Enter أو زر الإرسال
|
| 46 |
+
4. يمكنك مسح المحادثة باستخدام زر Clear
|
| 47 |
|
| 48 |
+
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
|
|
|
|
|
|
|
|
app.py
CHANGED
|
@@ -1,24 +1,33 @@
|
|
| 1 |
-
|
| 2 |
-
from pydantic import BaseModel
|
| 3 |
from auto_responder import AutoResponder
|
| 4 |
-
import uvicorn
|
| 5 |
|
| 6 |
-
app = FastAPI(title="AI Auto Responder")
|
| 7 |
responder = AutoResponder()
|
| 8 |
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
sender_id
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 12 |
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
return
|
| 17 |
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 22 |
|
|
|
|
| 23 |
if __name__ == "__main__":
|
| 24 |
-
|
|
|
|
| 1 |
+
import gradio as gr
|
|
|
|
| 2 |
from auto_responder import AutoResponder
|
|
|
|
| 3 |
|
|
|
|
| 4 |
responder = AutoResponder()
|
| 5 |
|
| 6 |
+
def chat(message, history):
|
| 7 |
+
"""Handle chat interaction"""
|
| 8 |
+
# Extract sender_id from history or use default
|
| 9 |
+
sender_id = "user123"
|
| 10 |
+
|
| 11 |
+
# Generate response
|
| 12 |
+
bot_message = responder.generate_response(message, sender_id)
|
| 13 |
+
|
| 14 |
+
return bot_message
|
| 15 |
|
| 16 |
+
def clear_chat_history():
|
| 17 |
+
"""Clear chat history"""
|
| 18 |
+
responder.clear_history("user123")
|
| 19 |
+
return None
|
| 20 |
|
| 21 |
+
# Create Gradio interface
|
| 22 |
+
demo = gr.ChatInterface(
|
| 23 |
+
fn=chat,
|
| 24 |
+
title="وكيل الرد التلقائي بالذكاء الاصطناعي",
|
| 25 |
+
description="محادثة مع وكيل ذكاء اصطناعي باستخدام نموذج Blenderbot المفتوح المصدر",
|
| 26 |
+
examples=["مرحبا!", "كيف حالك؟", "ما هو الطقس اليوم؟"],
|
| 27 |
+
theme="soft",
|
| 28 |
+
clear_btn=True,
|
| 29 |
+
)
|
| 30 |
|
| 31 |
+
# Launch the app
|
| 32 |
if __name__ == "__main__":
|
| 33 |
+
demo.launch()
|
requirements.txt
CHANGED
|
@@ -1,6 +1,4 @@
|
|
| 1 |
transformers==4.36.2
|
| 2 |
torch==2.1.2
|
| 3 |
sentencepiece==0.1.99
|
| 4 |
-
|
| 5 |
-
uvicorn==0.27.0
|
| 6 |
-
pydantic==2.5.3
|
|
|
|
| 1 |
transformers==4.36.2
|
| 2 |
torch==2.1.2
|
| 3 |
sentencepiece==0.1.99
|
| 4 |
+
gradio==4.12.0
|
|
|
|
|
|