بواسطة morbah |
أداة إنشاء الصور بـ Gemini AI (Flash 1.5)
أداة إنشاء الصور بالذكاء الاصطناعي (Gemini 1.5 Flash)
أدخل وصفًا تفصيليًا للصورة التي ترغب في إنشائها:
جاري إنشاء الصورة... الرجاء الانتظار قليلاً.
<!--DOCTYPE html-->
<html>
<head>
<title>أداة إنشاء الصور بـ Gemini AI (Flash 1.5)</title>
<style>
body {
font-family: Arial, sans-serif;
background-color: #f0f2f5;
color: #333;
margin: 0;
padding: 20px;
display: flex;
flex-direction: column;
align-items: center;
}
.container {
background-color: #fff;
padding: 30px;
border-radius: 8px;
box-shadow: 0 4px 10px rgba(0, 0, 0, 0.1);
width: 90%;
max-width: 800px;
text-align: center;
}
h1 {
color: #0056b3;
margin-bottom: 25px;
}
textarea {
width: calc(100% - 20px);
padding: 12px;
margin-bottom: 20px;
border: 1px solid #ddd;
border-radius: 5px;
font-size: 16px;
resize: vertical;
min-height: 100px;
}
button {
background-color: #007bff;
color: white;
padding: 12px 25px;
border: none;
border-radius: 5px;
cursor: pointer;
font-size: 18px;
transition: background-color 0.3s ease;
}
button:hover {
background-color: #0056b3;
}
.image-gallery {
margin-top: 30px;
display: flex;
flex-wrap: wrap;
justify-content: center;
gap: 15px;
}
.image-gallery img {
max-width: 100%;
height: auto;
border: 1px solid #ddd;
border-radius: 5px;
box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
}
.loading {
margin-top: 20px;
font-size: 18px;
color: #007bff;
display: none; /* مخفي افتراضيًا */
}
.error {
margin-top: 20px;
font-size: 18px;
color: #dc3545;
display: none; /* مخفي افتراضيًا */
}
</style>
</head>
<body>
<div class="container">
<h1>أداة إنشاء الصور بالذكاء الاصطناعي (Gemini 1.5 Flash)</h1>
<p>أدخل وصفًا تفصيليًا للصورة التي ترغب في إنشائها:</p>
<textarea id="promptInput" placeholder="مثال: قطة لطيفة ترتدي قبعة ساحر وتجلس على كتب قديمة في مكتبة مضاءة"></textarea>
<button onclick="generateImage()">إنشاء الصورة</button>
<div class="loading" id="loadingMessage">جاري إنشاء الصورة... الرجاء الانتظار قليلاً.</div>
<div class="error" id="errorMessage"></div>
<div class="image-gallery" id="imageGallery">
<!-- هنا ستظهر الصور التي تم إنشاؤها -->
</div>
</div>
<script>
// **مفتاح Gemini API الخاص بك - تم وضعه بناءً على طلبك**
const GEMINI_API_KEY = "AIzaSyCCTBriQK0-_gG_Le5syt9BuViJb6W4vJA";
// **تم تغيير اسم النموذج إلى gemini-1.5-flash بناءً على طلبك**
const GEMINI_MODEL_NAME = "gemini-2.5-flash";
async function generateImage() {
const prompt = document.getElementById('promptInput').value;
const loadingMessage = document.getElementById('loadingMessage');
const errorMessage = document.getElementById('errorMessage');
const imageGallery = document.getElementById('imageGallery');
if (!prompt) {
errorMessage.textContent = 'الرجاء إدخال وصف للصورة.';
errorMessage.style.display = 'block';
return;
}
loadingMessage.style.display = 'block';
errorMessage.style.display = 'none';
imageGallery.innerHTML = ''; // مسح الصور السابقة
try {
// بناء طلب الـ API لـ Gemini 1.5 Flash
// كما ذكرت سابقًا، هذا النموذج هو نصي بالأساس.
// سيرسل الطلب ويستقبل استجابة نصية.
const response = await fetch(`https://generativelanguage.googleapis.com/v1beta/models/${GEMINI_MODEL_NAME}:generateContent?key=${GEMINI_API_KEY}`, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({
contents: [{
parts: [{
text: `Generate a high-quality, detailed image based on this description: ${prompt}. Focus on artistic quality and visual appeal.`
}]
}],
// يمكنك إضافة ضبط لـ generationConfig هنا إذا أردت، مثل temperature, topP, topK
// generationConfig: {
// temperature: 0.9,
// topP: 1,
// topK: 1,
// }
}),
});
const data = await response.json();
if (data && data.candidates && data.candidates.length > 0 && data.candidates[0].content && data.candidates[0].content.parts && data.candidates[0].content.parts.length > 0) {
const generatedText = data.candidates[0].content.parts[0].text;
// **مرة أخرى، هذا هو الجزء الذي يحتاج إلى خدمة توليد صور حقيقية.**
// Gemini 1.5 Flash سينتج نصًا هنا.
// لعرض صورة حقيقية، يجب استبدال هذا برابط API لخدمة مثل DALL-E أو Stable Diffusion.
// لغرض العرض التوضيحي، سنستمر في استخدام صورة placeholder.
const imageUrl = `https://via.placeholder.com/600x400?text=${encodeURIComponent(prompt)}`;
const img = document.createElement('img');
img.src = imageUrl;
img.alt = prompt;
imageGallery.appendChild(img);
} else {
errorMessage.textContent = 'لم يتمكن الذكاء الاصطناعي من إنشاء صورة بالوصف المقدم. الرجاء المحاولة بوصف مختلف.';
errorMessage.style.display = 'block';
}
} catch (error) {
console.error('Error generating image:', error);
errorMessage.textContent = 'حدث خطأ أثناء الاتصال بالذكاء الاصطناعي. الرجاء المحاولة مرة أخرى.';
errorMessage.style.display = 'block';
} finally {
loadingMessage.style.display = 'none';
}
}
</script>
</body>
</html>
انا مهتم بمجال التقنية والربح من الانترنت واتطلع لنشر المزيد من المقالات التي تفيدكم
تعليقات
إرسال تعليق