Rooni commited on
Commit
b2b3945
·
1 Parent(s): 813ad8b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -3
app.py CHANGED
@@ -3,6 +3,9 @@ import requests
3
  import json
4
  import os
5
  import markdown2
 
 
 
6
 
7
  def generate_minecraft_command(description):
8
  headers = {
@@ -12,7 +15,7 @@ def generate_minecraft_command(description):
12
 
13
  payload = {
14
  'messages': [{'role': 'system', 'content': f'{description}'}],
15
- 'max_tokens': 100000,
16
  'model': os.getenv("MODEL")
17
  }
18
 
@@ -24,7 +27,13 @@ def generate_minecraft_command(description):
24
 
25
  # Преобразование Markdown в HTML
26
  command_html = markdown2.markdown(command)
27
- return command_html
 
 
 
 
 
 
28
  elif 'error' in data:
29
  error_message = data['error']['message']
30
  return f'Ошибка: {error_message}'
@@ -33,5 +42,5 @@ def generate_minecraft_command(description):
33
 
34
  iface = gr.Interface(fn=generate_minecraft_command, inputs=[
35
  gr.Textbox(label="Запрос")
36
- ], outputs=gr.HTML(label="Ответ"), title="GPT") # Используем gr.HTML вместо gr.Textbox
37
  iface.launch()
 
3
  import json
4
  import os
5
  import markdown2
6
+ from pygments import highlight
7
+ from pygments.lexers import get_lexer_by_name
8
+ from pygments.formatters import HtmlFormatter
9
 
10
  def generate_minecraft_command(description):
11
  headers = {
 
15
 
16
  payload = {
17
  'messages': [{'role': 'system', 'content': f'{description}'}],
18
+ 'max_tokens': 10000,
19
  'model': os.getenv("MODEL")
20
  }
21
 
 
27
 
28
  # Преобразование Markdown в HTML
29
  command_html = markdown2.markdown(command)
30
+
31
+ # Подсветка синтаксиса кода
32
+ lexer = get_lexer_by_name("html", stripall=True)
33
+ formatter = HtmlFormatter(style="colorful", full=True, noclasses=True)
34
+ highlighted_code = highlight(command, lexer, formatter)
35
+
36
+ return highlighted_code
37
  elif 'error' in data:
38
  error_message = data['error']['message']
39
  return f'Ошибка: {error_message}'
 
42
 
43
  iface = gr.Interface(fn=generate_minecraft_command, inputs=[
44
  gr.Textbox(label="Запрос")
45
+ ], outputs=gr.HTML(label="Ответ", html=True), title="GPT")
46
  iface.launch()