enotkrutoy commited on
Commit
147a1bd
·
verified ·
1 Parent(s): eb2b526

Update appp.py

Browse files
Files changed (1) hide show
  1. appp.py +57 -64
appp.py CHANGED
@@ -1,86 +1,79 @@
1
  import gradio as gr
2
  import requests
3
  import json
4
- import groq
5
 
6
- # Function to interact with the Groq API using the curl request approach
7
- def chat_function(message):
8
- # Define the request payload
 
 
 
 
9
  payload = {
10
  "model": "mixtral-8x7b-32768",
11
  "messages": [
12
- {"role": "user", "content": message}
 
13
  ]
14
  }
15
-
16
  headers = {
17
  "Content-Type": "application/json",
18
- "Authorization": "Bearer gsk_yKXR75Se0OxdULncf1YDWGjRbmQTYjvSmwaAKgcq0l" # Replace with your API key
19
  }
20
-
21
  try:
22
  response = requests.post("https://api.groq.com/openai/v1/chat/completions", headers=headers, data=json.dumps(payload))
23
-
24
  if response.status_code == 200:
25
  data = response.json()
26
- return data["choices"][0]["message"]["content"]
 
27
  else:
28
- return f"Error: {response.status_code}, {response.text}"
29
  except requests.exceptions.RequestException as e:
30
- return f"Error: {e}"
31
-
32
- # Function to interact with the Groq API for leak report analysis
33
- def leak_report_function(message):
34
- # Define the request payload
35
- payload = {
36
- "model": "llama3-8b-8192",
37
- "messages": [
38
- {
39
- "role": "system",
40
- "content": "Вы являетесь системой, анализирующей утечки в безопасном режиме, "
41
- "avoid sharing sensitive personal or confidential data. "
42
- "Generate leak report details in a JSON structure with the following format in Russian:\n"
43
- f"{json.dumps(LeakReport.model_json_schema(), indent=2)}"
44
- },
45
- {
46
- "role": "user",
47
- "content": f"Сгенерируйте отчет о потенциальных утечках для следующих данных без включения конфиденциальных данных (отчет должен быть на русском языке):\n"
48
- f"{message}"
49
- },
50
- ],
51
- "temperature": 0,
52
- "stream": False,
53
- "response_format": {"type": "json_object"},
54
- }
55
 
56
- try:
57
- chat_completion = groq.chat.completions.create(payload)
 
 
 
 
 
 
58
 
59
- result_json = json.loads(chat_completion.choices[0].message.content)
60
- return result_json
61
- except requests.exceptions.RequestException as e:
62
- return f"Error: {e}"
 
 
 
 
63
 
64
- # Set up Gradio interface
65
- gr.Interface(
66
- fn=chat_function,
67
- inputs=gr.Textbox(placeholder="Ask something..."),
68
- outputs="text",
69
- title="Groq-Gradio Chat",
70
- theme="default",
71
- examples=[
72
- "Tell me a short story about a puppy",
73
- "Write a 14-line poem about travelling in Shakespeare style",
74
- "What are the wonders of the world?",
75
- "List the countries in Africa and their capitals"
76
- ]
77
- ).launch()
 
 
 
 
 
 
 
 
 
 
 
 
78
 
79
- # Set up Gradio interface for leak report analysis
80
- gr.Interface(
81
- fn=leak_report_function,
82
- inputs=gr.Textbox(placeholder="Enter data for leak report..."),
83
- outputs="json",
84
- title="Groq-Gradio Leak Report",
85
- theme="default",
86
- ).launch(share=True)
 
1
  import gradio as gr
2
  import requests
3
  import json
 
4
 
5
+ # Ключевая информация из JSON
6
+ SYSTEM_NAME = "WhiteRabbitNeo"
7
+ SYSTEM_VERSION = "Beta-AI"
8
+ SYSTEM_DESCRIPTION = "Система поддержки команды Red Team, предназначенная для анализа, улучшения и проверки кода."
9
+
10
+ # Функция анализа и обработки кода
11
+ def analyze_code(input_code):
12
  payload = {
13
  "model": "mixtral-8x7b-32768",
14
  "messages": [
15
+ {"role": "system", "content": f"Вы используете {SYSTEM_NAME} версии {SYSTEM_VERSION}. {SYSTEM_DESCRIPTION}"},
16
+ {"role": "user", "content": input_code}
17
  ]
18
  }
 
19
  headers = {
20
  "Content-Type": "application/json",
21
+ "Authorization": "Bearer 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"
22
  }
 
23
  try:
24
  response = requests.post("https://api.groq.com/openai/v1/chat/completions", headers=headers, data=json.dumps(payload))
 
25
  if response.status_code == 200:
26
  data = response.json()
27
+ analysis = data.get("choices", [{}])[0].get("message", {}).get("content", "No content available")
28
+ return analysis
29
  else:
30
+ return f"Ошибка: {response.status_code}, {response.text}"
31
  except requests.exceptions.RequestException as e:
32
+ return f"Ошибка при выполнении запроса: {e}"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
33
 
34
+ # Стилизация интерфейса в стиле нейропанка
35
+ neuropunk_theme = {
36
+ "background": "linear-gradient(135deg, #0f0c29, #302b63, #24243e)", # Градиент
37
+ "text_color": "#E6E6FA", # Лавандовый текст
38
+ "button_color": "#ff007f", # Яркие кнопки
39
+ "textbox_color": "#141414", # Фон ввода
40
+ "border_radius": "12px", # Скругление углов
41
+ }
42
 
43
+ # Интерфейс Gradio
44
+ def style_widget(widget, styles):
45
+ widget.style(
46
+ rounded=True,
47
+ background_color=styles.get("textbox_color"),
48
+ text_color=styles.get("text_color"),
49
+ border_width=1
50
+ )
51
 
52
+ with gr.Blocks() as app:
53
+ with gr.Row():
54
+ gr.Markdown(
55
+ f"# {SYSTEM_NAME} — {SYSTEM_DESCRIPTION}\n\n*Версия*: {SYSTEM_VERSION}",
56
+ elem_id="header",
57
+ style={"color": neuropunk_theme["text_color"], "text_align": "center"}
58
+ )
59
+ with gr.Row():
60
+ code_input = gr.Textbox(
61
+ placeholder="Введите ваш код или текст для анализа...",
62
+ lines=8,
63
+ elem_id="code_input"
64
+ )
65
+ style_widget(code_input, neuropunk_theme)
66
+ with gr.Row():
67
+ output_display = gr.Textbox(
68
+ placeholder="Результат анализа появится здесь...",
69
+ lines=10,
70
+ elem_id="output_display",
71
+ interactive=False
72
+ )
73
+ style_widget(output_display, neuropunk_theme)
74
+ with gr.Row():
75
+ analyze_button = gr.Button("Проанализировать")
76
+ analyze_button.click(analyze_code, inputs=[code_input], outputs=[output_display])
77
+ style_widget(analyze_button, neuropunk_theme)
78
 
79
+ app.launch(share=True)