Spaces:
Running
Running
Commit History
-
<!DOCTYPE html>
Verified signature<html lang="ar"> <head> <meta charset="UTF-8"> <title>تحليل الوسائط الإعلامية</title> <style> body { font-family: Arial; direction: rtl; margin: 20px; } textarea { width: 100%; } #result { white-space: pre-wrap; background: #f3f3f3; padding: 10px; margin-top: 20px; } img { max-width: 300px; display: block; margin-top: 10px; } </style> </head> <body> <h1>تحليل الوسائط الإعلامية</h1> <form id="analyzeForm"> <label>نص التحليل:</label><br> <textarea name="userText" rows="4" placeholder="أدخل نص التحليل هنا"></textarea><br><br> <label>اختر صورة:</label><br> <input type="file" name="media" accept="image/*" required><br><br> <button type="submit">تحليل</button> </form> <div id="preview"></div> <div id="result"></div> <script> const AZURE_ENDPOINT = "https://lahja-dev-resource2.openai.azure.com/openai/deployments/Wasm-V1/chat/completions?api-version=2025-01-01-preview"; const AZURE_API_KEY = "E7k8z3ADEUi2DZ1dl9pHlSTeUSoKb3jVjg5zYDAPNHBHKBfXlbTFJQQJ99BJACHYHv6XJ3w3AAAAACO…ad50e1c -
function encodeImageToBase64(filePath) {
Verified signatureconst buffer = fs.readFileSync(filePath); const ext = filePath.split('.').pop(); return `data:image/${ext};base64,${buffer.toString('base64')}`; } // الدالة الرئيسية لإرسال POST والحصول على النتيجة async function analyzeMedia(userText) { const media_url = encodeImageToBase64(IMAGE_PATH); // بناء chat prompt كنص فقط (لأن نموذج النصوص لا يدعم image_url مباشرة) const chat_prompt = [ { role: "system", content: "تحليل الوسائط الإعلامية" }, { role: "user", content: `${userText}\nالصورة: ${media_url}` } ]; try { const response = await fetch(AZURE_ENDPOINT, { method: "POST", headers: { "Content-Type": "application/json", "api-key": AZURE_API_KEY }, body: JSON.stringify({ model: DEPLOYMENT, messages: chat_prompt, max_completion_tokens: 1024, stream: false }) }); if (!response.ok) { const text = await response.text(); throw new Error(`Azure API error ${response.status}:…8ea1c7f -
function encodeImageToBase64(filePath) {
Verified signatureconst buffer = fs.readFileSync(filePath); const ext = filePath.split('.').pop(); return `data:image/${ext};base64,${buffer.toString('base64')}`; } // الدالة الرئيسية لإرسال POST والحصول على النتيجة async function analyzeMedia(userText) { const media_url = encodeImageToBase64(IMAGE_PATH); // بناء chat prompt كنص فقط (لأن نموذج النصوص لا يدعم image_url مباشرة) const chat_prompt = [ { role: "system", content: "تحليل الوسائط الإعلامية" }, { role: "user", content: `${userText}\nالصورة: ${media_url}` } ]; try { const response = await fetch(AZURE_ENDPOINT, { method: "POST", headers: { "Content-Type": "application/json", "api-key": AZURE_API_KEY }, body: JSON.stringify({ model: DEPLOYMENT, messages: chat_prompt, max_completion_tokens: 1024, stream: false }) }); if (!response.ok) { const text = await response.text(); throw new Error(`Azure API error ${response.status}:…19a3392 -
import os
Verified signatureimport base64 from openai import AzureOpenAI endpoint = os.getenv("ENDPOINT_URL", "https://lahja-dev-resource2.openai.azure.com/openai/deployments/Wasm-V1/chat/completions?api-version=2025-01-01-preview") deployment = os.getenv("DEPLOYMENT_NAME", "Wasm-V1") subscription_key = os.getenv("AZURE_OPENAI_API_KEY", "E7k8z3ADEUi2DZ1dl9pHlSTeUSoKb3jVjg5zYDAPNHBHKBfXlbTFJQQJ99BJACHYHv6XJ3w3AAAAACOGyF4Z") # Initialize Azure OpenAI client with key-based authentication client = AzureOpenAI( azure_endpoint=endpoint, api_key=subscription_key, api_version="2025-01-01-preview", ) IMAGE_PATH = "/content/تنزيل.jpg" encoded_image = base64.b64encode(open(IMAGE_PATH, 'rb').read()).decode('ascii') # Prepare the chat prompt chat_prompt = [ { "role": "system", "content": [ { "type": "text", "text":PROMPT_MEDIA_ANALYSIS }, # Removed the extra closing bracket here ] }, { "role": "user", "c…a478300 -
import fs from "fs";
Verified signatureimport fetch from "node-fetch"; // إعداد المتغيرات const AZURE_ENDPOINT = "https://lahja-dev-resource2.openai.azure.com/openai/deployments/Wasm-V1/chat/completions?api-version=2025-01-01-preview"; const AZURE_API_KEY = "E7k8z3ADEUi2DZ1dl9pHlSTeUSoKb3jVjg5zYDAPNHBHKBfXlbTFJQQJ99BJACHYHv6XJ3w3AAAAACOGyF4Z"; const DEPLOYMENT = "Wasm-V1"; const PROMPT_MEDIA_ANALYSIS = "ضع هنا محتوى النظام لتحليل الوسائط"; // دالة لإنشاء Base64 من الصورة function encodeImageToBase64(filePath) { const buffer = fs.readFileSync(filePath); const ext = filePath.split('.').pop(); return `data:image/${ext};base64,${buffer.toString('base64')}`; } // البيانات للإرسال const userText = "تحليل محتوى الوسائط المرفقة"; const filePath = "./test_image.jpg"; // ضع مسار الصورة هنا const media_url = encodeImageToBase64(filePath); // بناء الرسائل (chat prompt) const chat_prompt = [ { role: "system", content: [ { type: "text", text: PROMPT_MEDIA_ANALYSIS } ] }, { role:…105f55a -
initial commit
Verified signatureb8a76af