Uniaff commited on
Commit
cb5e151
·
verified ·
1 Parent(s): bc8831f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +36 -30
app.py CHANGED
@@ -10,8 +10,6 @@ import subprocess
10
  from func_ai import classify_comment, retrieve_from_vdb, VECTOR_API_URL
11
  from func_facebook import get_page_id, has_page_replied, get_unanswered_comments, reply_comment, hide_negative_comments
12
 
13
-
14
-
15
  # Wait for the server to start
16
  time.sleep(10)
17
  llm = Ollama(model="llama3.1")
@@ -74,44 +72,54 @@ def generate_response(user_query):
74
 
75
  def process_comments(ACCESS_TOKEN):
76
  print("Начинаем процесс скрытия отрицательных комментариев.")
77
- result_hide_comments = hide_negative_comments(ACCESS_TOKEN)
78
- print(f"Количество скрытых комментариев: {result_hide_comments}")
79
 
80
  print("Получение неотвеченных комментариев.")
81
- comments = get_unanswered_comments(ACCESS_TOKEN)
82
- unanswered_comments = []
83
- page_id = get_page_id(ACCESS_TOKEN)
84
 
 
85
  if not page_id:
86
  print("Не удалось получить ID страницы.")
87
  return {"status": "failed", "reason": "Не удалось получить ID страницы."}
88
 
89
  print(f"ID страницы: {page_id}")
90
 
91
- for comment in comments:
92
- if comment.get('is_hidden', False):
93
- print(f"Комментарий скрыт: {comment['id']}")
94
- continue
95
- comment_id = comment['id']
96
- if not has_page_replied(comment_id, page_id, ACCESS_TOKEN):
97
- unanswered_comments.append(comment)
98
-
99
- print(f"Найдено {len(unanswered_comments)} неотвеченных комментариев.")
100
-
101
- for comment in unanswered_comments:
102
- message = comment['message']
103
- print(f"Обработка комментария: {message}")
104
- classification = classify_comment(message)
105
- print(f"Классификация комментария: {classification}")
106
- if classification == "interrogative":
107
- response_message = generate_response(message)
108
- print(f"Ответ на комментарий: {response_message}")
109
- reply_comment(message=response_message, comment_id=comment['id'], token=ACCESS_TOKEN)
 
 
 
 
 
 
 
 
 
 
 
 
110
 
111
  return {
112
  "status": "completed",
113
- "processed_comments": len(unanswered_comments),
114
- "hidden_comments": result_hide_comments
115
  }
116
 
117
 
@@ -133,8 +141,6 @@ with gr.Blocks() as demo:
133
  if __name__ == "__main__":
134
  demo.launch(
135
  debug=True,
136
- # share=True if "True" in sys.argv else False,
137
- # inbrowser=True if "--open" in sys.argv else False,
138
  server_port=7860,
139
  server_name="0.0.0.0",
140
  )
 
10
  from func_ai import classify_comment, retrieve_from_vdb, VECTOR_API_URL
11
  from func_facebook import get_page_id, has_page_replied, get_unanswered_comments, reply_comment, hide_negative_comments
12
 
 
 
13
  # Wait for the server to start
14
  time.sleep(10)
15
  llm = Ollama(model="llama3.1")
 
72
 
73
  def process_comments(ACCESS_TOKEN):
74
  print("Начинаем процесс скрытия отрицательных комментариев.")
75
+ hidden_comments_data = hide_negative_comments(ACCESS_TOKEN)
76
+ print(f"Количество постов с скрытыми комментариями: {len(hidden_comments_data)}")
77
 
78
  print("Получение неотвеченных комментариев.")
79
+ posts_with_unanswered_comments = get_unanswered_comments(ACCESS_TOKEN)
 
 
80
 
81
+ page_id = get_page_id(ACCESS_TOKEN)
82
  if not page_id:
83
  print("Не удалось получить ID страницы.")
84
  return {"status": "failed", "reason": "Не удалось получить ID страницы."}
85
 
86
  print(f"ID страницы: {page_id}")
87
 
88
+ processed_posts = []
89
+
90
+ for post_data in posts_with_unanswered_comments:
91
+ post_id = post_data['post_id']
92
+ post_message = post_data['post_message']
93
+ unanswered_comments = post_data['unanswered_comments']
94
+
95
+ post_replies = []
96
+
97
+ for comment in unanswered_comments:
98
+ message = comment['message']
99
+ print(f"Обработка комментария: {message}")
100
+ classification = classify_comment(message)
101
+ print(f"Классификация комментария: {classification}")
102
+ if classification == "interrogative":
103
+ response_message = generate_response(message)
104
+ print(f"Ответ на комментарий: {response_message}")
105
+ success = reply_comment(comment_id=comment['id'], message=response_message, token=ACCESS_TOKEN)
106
+ if success:
107
+ post_replies.append({
108
+ 'comment_id': comment['id'],
109
+ 'comment_message': comment['message'],
110
+ 'reply_message': response_message
111
+ })
112
+
113
+ processed_posts.append({
114
+ 'post_id': post_id,
115
+ 'post_message': post_message,
116
+ 'hidden_comments': next((item['hidden_comments'] for item in hidden_comments_data if item['post_id'] == post_id), []),
117
+ 'replies': post_replies
118
+ })
119
 
120
  return {
121
  "status": "completed",
122
+ "posts": processed_posts
 
123
  }
124
 
125
 
 
141
  if __name__ == "__main__":
142
  demo.launch(
143
  debug=True,
 
 
144
  server_port=7860,
145
  server_name="0.0.0.0",
146
  )