MASTERYZ commited on
Commit
868c795
·
verified ·
1 Parent(s): cb86ca2

Update index.html

Browse files
Files changed (1) hide show
  1. index.html +26 -18
index.html CHANGED
@@ -66,6 +66,11 @@
66
  border: 1px solid #334155;
67
  }
68
  </style>
 
 
 
 
 
69
  </head>
70
  <body>
71
 
@@ -73,42 +78,45 @@
73
  <h1>🤖 Yapay Zeka Asistanı</h1>
74
  <p>Sorunuzu yazın, yapay zeka sizin için yanıtlasın:</p>
75
  <textarea id="userInput" placeholder="Buraya bir şeyler yazın..."></textarea>
76
- <button onclick="askAI()">Yapay Zekaya Sor</button>
77
  <div class="response" id="output">Yanıt burada görünecek...</div>
78
  </div>
79
 
80
  <script>
 
 
81
  async function askAI() {
82
  const prompt = document.getElementById('userInput').value;
83
  const output = document.getElementById('output');
 
84
 
85
  if (!prompt) {
86
  output.innerText = "Lütfen bir soru girin!";
87
  return;
88
  }
89
 
90
- output.innerText = "Düşünüyor...";
91
-
92
  try {
93
- const response = await fetch("https://router.huggingface.co/hf-inference/v1/chat/completions", {
94
- method: "POST",
95
- headers: {
96
- "Content-Type": "application/json"
97
- },
98
- body: JSON.stringify({
99
- model: "Qwen/Qwen2.5-Coder-32B-Instruct",
100
- messages: [{ role: "user", content: prompt }]
101
- })
102
- });
103
 
104
- const data = await response.json();
105
- if (data.choices && data.choices.length > 0) {
106
- output.innerText = data.choices[0].message.content;
107
- } else {
108
- output.innerText = "Bir yanıt alınamadı.";
109
  }
 
 
 
 
 
 
 
 
 
 
 
110
  } catch (error) {
111
  output.innerText = "Hata oluştu: " + error.message;
 
 
112
  }
113
  }
114
  </script>
 
66
  border: 1px solid #334155;
67
  }
68
  </style>
69
+ <!-- Hugging Face JS Kütüphanesi -->
70
+ <script type="module">
71
+ import { pipeline } from 'https://cdn.jsdelivr.net/npm/@xenova/transformers@2.6.0';
72
+ window.pipeline = pipeline;
73
+ </script>
74
  </head>
75
  <body>
76
 
 
78
  <h1>🤖 Yapay Zeka Asistanı</h1>
79
  <p>Sorunuzu yazın, yapay zeka sizin için yanıtlasın:</p>
80
  <textarea id="userInput" placeholder="Buraya bir şeyler yazın..."></textarea>
81
+ <button id="btn" onclick="askAI()">Yapay Zekaya Sor</button>
82
  <div class="response" id="output">Yanıt burada görünecek...</div>
83
  </div>
84
 
85
  <script>
86
+ let generator = null;
87
+
88
  async function askAI() {
89
  const prompt = document.getElementById('userInput').value;
90
  const output = document.getElementById('output');
91
+ const btn = document.getElementById('btn');
92
 
93
  if (!prompt) {
94
  output.innerText = "Lütfen bir soru girin!";
95
  return;
96
  }
97
 
 
 
98
  try {
99
+ btn.disabled = true;
 
 
 
 
 
 
 
 
 
100
 
101
+ if (!generator) {
102
+ output.innerText = "Model ilk kez yükleniyor (biraz zaman alabilir)...";
103
+ generator = await window.pipeline('text-generation', 'Xenova/Qwen1.5-0.5B-Chat');
 
 
104
  }
105
+
106
+ output.innerText = "Düşünüyor...";
107
+
108
+ const messages = [
109
+ { role: "system", content: "Sen Türkçe cevap veren yardımsever bir yapay zeka asistanısın." },
110
+ { role: "user", content: prompt }
111
+ ];
112
+
113
+ const result = await generator(prompt, { max_new_tokens: 100 });
114
+ output.innerText = result[0].generated_text;
115
+
116
  } catch (error) {
117
  output.innerText = "Hata oluştu: " + error.message;
118
+ } finally {
119
+ btn.disabled = false;
120
  }
121
  }
122
  </script>