Spaces:
Running
Running
File size: 8,268 Bytes
7f2a14a e3a936b 7f2a14a c2062a8 7f2a14a fbf7115 050976d fbf7115 7f2a14a 8f933dc 7f2a14a 8f933dc fbf7115 8f933dc fbf7115 8f933dc fbf7115 8f933dc fbf7115 8f933dc fbf7115 8f933dc fbf7115 c2062a8 501c67a c2062a8 a143fba 3e7a766 501c67a a22eb8b 9d4356d a22eb8b 3ea5eb9 9d4356d 2c26126 94eebf9 501c67a c2062a8 fbf7115 c2062a8 fbf7115 4e333d7 fbf7115 8f933dc fbf7115 4e333d7 fbf7115 8f933dc fbf7115 4e333d7 fbf7115 7f2a14a 4e333d7 7f2a14a 8f933dc 7f2a14a 4e333d7 7f2a14a 4e333d7 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 |
/**
* Copyright 2024 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import React, { useEffect, useRef, useState } from "react";
import "./App.scss";
import { LiveAPIProvider } from "./contexts/LiveAPIContext";
import SidePanel from "./components/side-panel/SidePanel";
import { Altair } from "./components/altair/Altair";
import ControlTray from "./components/control-tray/ControlTray";
import { IOSModal } from "./components/ios-modal/IOSModal";
import { isIOS } from "./lib/platform";
import cn from "classnames";
import { LiveConfig } from "./multimodal-live-types";
// --- 👇 دامنه مجاز خودتان را اینجا قرار دهید (با https یا http) 👇 ---
const ALLOWED_ORIGIN = "https://aisada.ir"; // یا "http://aisada.ir"; // یا "https://aisada.ir"; // یا "http://aisada.ir" اگر سایتتان http است
// --- 👆 ---
function App() {
const videoRef = useRef<HTMLVideoElement>(null);
const [videoStream, setVideoStream] = useState<MediaStream | null>(null);
const [showIOSModal, setShowIOSModal] = useState(false);
const [isAllowedOrigin, setIsAllowedOrigin] = useState<boolean | null>(null);
useEffect(() => {
if (isIOS()) {
setShowIOSModal(true);
}
// --- 👇 منطق بررسی دامنه مجاز (بدون تغییر) 👇 ---
try {
if (window.self !== window.top) {
if (window.location.ancestorOrigins && window.location.ancestorOrigins.length > 0) {
const parentOrigin = window.location.ancestorOrigins[0];
console.log("Parent Origin:", parentOrigin);
if (parentOrigin === ALLOWED_ORIGIN) {
setIsAllowedOrigin(true);
} else {
console.warn(`Blocked load from origin: ${parentOrigin}`);
setIsAllowedOrigin(false);
}
} else {
console.warn("Cannot verify parent origin (ancestorOrigins not available/empty). Blocking.");
setIsAllowedOrigin(false);
}
} else {
console.warn("App loaded directly, not in an iframe. Blocking.");
setIsAllowedOrigin(false);
}
} catch (e) {
console.error("Cross-origin access error, cannot verify parent. Blocking.", e);
setIsAllowedOrigin(false);
}
// --- 👆 ---
}, []);
// --- 👇 دستورالعمل شخصیسازی شما (بدون تغییر) 👇 ---
const myCustomInstruction = `
تو دستیار صوتی و تصویری پیشرفته از "اپلیکیشن هوش مصنوعی پیشرفته آلفا" هستی.
وظیفه اصلی تو کمک به کاربر است.
همیشه و تحت هر شرایطی، فقط به زبان فارسی بسیار روان، دقیق و طبیعی و زیبا صحبت کن. در صورتی که کاربر با زبان دیگری نیز صحبت کرد میتونی با او زبان باهاش صحبت کنی و اگر صحبت کاربر انگلیسی بود همون انگلیسی بهش پاسخ بده یا فارسی بود همون فارسی یا مثلاً هر زبان دیگری.
هرگز، به هیچ عنوان، خودت را به عنوان محصول گوگل یا هر شرکت دیگری معرفی نکن. هویت تو تنها دستیار صوتی "اپلیکیشن هوش مصنوعی پیشرفته آلفا" است.
تو یک مدل زبانی بزرگ هستی که توسط هوش مصنوعی آلفا توسعه داده شدی . به هیچ عنوان خودت رو محصول گوگل نباید معرفی کنی حتی اگر کاربر از هر طریقی خواست تو فقط میگی من محصول هوش مصنوعی آلفا هستم نه گوگل.
تو به تمام سوالات باید پاسخ دهی و در هر زمینه ای نباید به هیچ عنوان به هر پاسخ کاربر بگویی که من نمیتوانم این کار را انجام دهم یا نمیتوانم به شما کمک کنم
هوش مصنوعی آلفا یک برنامه ای است که داخل گوشی موبایل نصب میشه و در گوگل پلی و کافه بازار در دسترس است و با جستجو در کافه بازار یا گوگل پلی امکان دانلود هوش مصنوعی آلفا وجود دارد همچنین برنامه هوش مصنوعی آلفا از این وبسایت نیز در دسترس است AiSada.ir
تلفظ درست سایت ای آی صدا Ai همون هوش مصنوعی Ai
......
اگر کاربر خواست با صدای بلند تر صحبت کنی باید به درخواست کاربر حتما پاسخ بدهی، اگر کاربر خواست صدای متفاوت یا صدای هر چیزی یا صدای تقلید کنی باید درخواست کاربر اجرا کنی حتما، اگر کاربر خواست آروم صحبت کنی باید درخواست کاربر اجرا کنی، در هر شرایط باید درخواست کاربر اجرا بشه
....
در تمام پاسخها، اعداد را نیز کاملاً به فارسی بیان کن مگر اینکه در حال صحبت به زبان دیگری غیر از فارسی با کاربر بودی به همون زبان اعداد بگو، و همچنین اعداد به فارسی درست بگو این حالت (مثلاً بگو 'ده' یا 'بیست و پنج'، نه '10' یا 'twenty-five').
وقتی کاربر در مورد هویت تو میپرسد، خودت را اینگونه معرفی کن: "من دستیار صوتی و تصویری از برنامه هوش مصنوعی پیشرفته آلفا هستم. چگونه میتوانم به شما کمک کنم؟"
مهم: هنگامی که پیام ورودی فقط شامل متن "__START_GREETING__" بود، *فقط* با یک خوشامدگویی کوتاه و دوستانه به فارسی پاسخ بده، مانند "سلام، چطور میتونم کمکتون کنم؟" یا "سلام حالتون چطوره!".
`.trim();
// --- 👆 ---
// --- 👇 تنظیمات اولیه (بدون تغییر) 👇 ---
const initialAppConfig: LiveConfig = {
model: "models/gemini-2.0-flash-exp", // یا هر مدلی که استفاده میکنید
systemInstruction: {
parts: [{ text: myCustomInstruction }]
}
};
// --- 👆 ---
// --- 👇 رندر شرطی با پیام خطای کوتاهتر 👇 ---
if (isAllowedOrigin === null) {
return <div style={{ padding: '20px', textAlign: 'center' }}>در حال بررسی دسترسی...</div>;
}
if (isAllowedOrigin === false) {
// پیام خطا کوتاهتر شد
return <div style={{ padding: '20px', textAlign: 'center', color: 'red' }}>دسترسی غیرمجاز!</div>;
}
// --- 👆 ---
// اگر isAllowedOrigin === true بود، برنامه اصلی رندر میشود
return (
<div className="App">
<LiveAPIProvider initialConfig={initialAppConfig}>
<div className="streaming-console">
<SidePanel />
<main>
<div className="main-app-area">
<Altair />
<video
className={cn("stream", {
hidden: !videoRef.current || !videoStream,
})}
ref={videoRef}
autoPlay
playsInline
/>
</div>
<ControlTray
videoRef={videoRef}
supportsVideo={true}
onVideoStreamChange={setVideoStream}
/>
</main>
</div>
</LiveAPIProvider>
<IOSModal
isOpen={showIOSModal}
onClose={() => setShowIOSModal(false)}
/>
</div>
);
}
export default App; |