Rooni commited on
Commit
28b84f1
·
1 Parent(s): 73af1d0

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +21 -2
app.py CHANGED
@@ -1,9 +1,28 @@
1
  import gradio as gr
2
  import os
3
 
4
- def gen(prompt):
5
- return f'WORK: {prompt}'
 
 
 
 
 
 
 
6
 
 
 
 
 
 
 
 
 
 
 
 
 
7
 
8
  css = """
9
  footer {visibility: hidden !important;}
 
1
  import gradio as gr
2
  import os
3
 
4
+ API_TOKEN = os.getenv("HF_READ_TOKEN")
5
+ headers = {"Authorization": f"Bearer {API_TOKEN}"}
6
+
7
+ def gen(prompt, model='gpt'):
8
+ if prompt == "" or prompt == None:
9
+ return None
10
+
11
+ if model == 'gpt':
12
+ API_URL = "https://api-inference.huggingface.co/models/openchat/openchat_3.5"
13
 
14
+ payload = {
15
+ "messages": [{"role": "user", "content": prompt}]
16
+ }
17
+
18
+ response = requests.post(API_URL, headers=headers, json=payload, timeout=timeout)
19
+ if response.status_code != 200:
20
+ print(f"Ошибка: Не удалось получить ответ. Статус ответа: {response.status_code}")
21
+ print(f"Содержимое ответа: {response.text}")
22
+ return "Произошла ошибка"
23
+
24
+ return response.json()
25
+
26
 
27
  css = """
28
  footer {visibility: hidden !important;}