Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,64 +1,30 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
from transformers import pipeline
|
| 3 |
-
import logging
|
| 4 |
-
|
| 5 |
-
# إعداد logging (يشبه terminal logs)
|
| 6 |
-
logging.basicConfig(level=logging.INFO)
|
| 7 |
-
|
| 8 |
-
logging.info("Starting Flogistic AI...")
|
| 9 |
|
| 10 |
# تحميل نموذج خفيف
|
| 11 |
-
generator = pipeline(
|
| 12 |
-
"text-generation",
|
| 13 |
-
model="distilgpt2"
|
| 14 |
-
)
|
| 15 |
-
|
| 16 |
-
# ذاكرة محادثة
|
| 17 |
-
chat_history = []
|
| 18 |
-
|
| 19 |
-
def generate_response(user_input):
|
| 20 |
-
global chat_history
|
| 21 |
-
|
| 22 |
-
logging.info(f"User Input: {user_input}")
|
| 23 |
-
|
| 24 |
-
prompt = ""
|
| 25 |
-
for u, a in chat_history:
|
| 26 |
-
prompt += f"User: {u}\nAI: {a}\n"
|
| 27 |
|
| 28 |
-
|
|
|
|
|
|
|
|
|
|
| 29 |
|
| 30 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 31 |
|
| 32 |
-
|
|
|
|
| 33 |
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
logging.info(f"AI Response: {response}")
|
| 37 |
-
|
| 38 |
-
return chat_history
|
| 39 |
-
|
| 40 |
-
# واجهة احترافية
|
| 41 |
with gr.Blocks() as demo:
|
| 42 |
-
gr.Markdown("#
|
| 43 |
|
| 44 |
chatbot = gr.Chatbot()
|
| 45 |
msg = gr.Textbox(placeholder="Type your message...")
|
| 46 |
|
| 47 |
-
def respond(message, history):
|
| 48 |
-
history = generate_response(message)
|
| 49 |
-
return "", history
|
| 50 |
-
|
| 51 |
msg.submit(respond, [msg, chatbot], [msg, chatbot])
|
| 52 |
|
| 53 |
-
demo.launch()
|
| 54 |
-
log_output = gr.Textbox(label="System Logs")
|
| 55 |
-
|
| 56 |
-
def respond_with_logs(message, history):
|
| 57 |
-
history = generate_response(message)
|
| 58 |
-
logs = f"Last input: {message}\nHistory length: {len(history)}"
|
| 59 |
-
return "", history, logs
|
| 60 |
-
msg.submit(
|
| 61 |
-
respond_with_logs,
|
| 62 |
-
[msg, chatbot],
|
| 63 |
-
[msg, chatbot, log_output]
|
| 64 |
-
)
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
from transformers import pipeline
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3 |
|
| 4 |
# تحميل نموذج خفيف
|
| 5 |
+
generator = pipeline("text-generation", model="distilgpt2")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 6 |
|
| 7 |
+
# الرد
|
| 8 |
+
def respond(message, chat_history):
|
| 9 |
+
if chat_history is None:
|
| 10 |
+
chat_history = []
|
| 11 |
|
| 12 |
+
response = generator(
|
| 13 |
+
message,
|
| 14 |
+
max_new_tokens=60,
|
| 15 |
+
do_sample=True
|
| 16 |
+
)[0]["generated_text"]
|
| 17 |
|
| 18 |
+
chat_history.append((message, response))
|
| 19 |
+
return "", chat_history
|
| 20 |
|
| 21 |
+
# واجهة بسيطة ومستقرة
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 22 |
with gr.Blocks() as demo:
|
| 23 |
+
gr.Markdown("# 🤖 Flogistic AI Assistant")
|
| 24 |
|
| 25 |
chatbot = gr.Chatbot()
|
| 26 |
msg = gr.Textbox(placeholder="Type your message...")
|
| 27 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 28 |
msg.submit(respond, [msg, chatbot], [msg, chatbot])
|
| 29 |
|
| 30 |
+
demo.launch()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|