EmeraldCreator commited on
Commit
2d73dda
·
verified ·
1 Parent(s): 6688a9c

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +39 -0
app.py ADDED
@@ -0,0 +1,39 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import pyodide_http
2
+ pyodide_http.patch_all()
3
+ import requests
4
+ import json
5
+
6
+ def get_answer(text, api_key):
7
+ # Прямая связь с OpenRouter
8
+ url = "https://openrouter.ai"
9
+
10
+ headers = {
11
+ "Authorization": f"Bearer {api_key}",
12
+ "Content-Type": "application/json"
13
+ }
14
+
15
+ # Полностью убрали характер. Только твой вопрос.
16
+ payload = {
17
+ "model": "google/gemma-2-9b-it:free",
18
+ "messages": [
19
+ {"role": "user", "content": text}
20
+ ],
21
+ "parameters": {
22
+ "max_new_tokens": 150,
23
+ "temperature": 0.7
24
+ }
25
+ }
26
+
27
+ try:
28
+ response = requests.post(url, headers=headers, data=json.dumps(payload), timeout=15)
29
+ data = response.json()
30
+
31
+ if 'choices' in data:
32
+ return data['choices']['message']['content'].strip()
33
+ else:
34
+ return "Ошибка! Проверь лимиты или ключ."
35
+ except:
36
+ return "Нет связи с сервером."
37
+
38
+ # Ждем данные из твоего index.html с Гитхаба
39
+ result = get_answer(user_input, openrouter_key)