Spaces:
Sleeping
Sleeping
optimize Summary
Browse files- pages/Summary.py +0 -41
pages/Summary.py
CHANGED
@@ -68,11 +68,6 @@ def generate_summary_with_claude(transcript, prompt_text):
|
|
68 |
}
|
69 |
]
|
70 |
)
|
71 |
-
|
72 |
-
# response_text = " ".join([block['text'] if isinstance(block, dict) and 'text' in block else str(block) for block in message.content])
|
73 |
-
# clean_summary = response_text.replace("\\n", " ").replace("TextBlock(text=", "").replace("type='text')", "")
|
74 |
-
# paragraphs = clean_summary.split('. ')
|
75 |
-
# formatted_summary = '\n\n'.join(paragraphs)
|
76 |
|
77 |
return message.content[0].text
|
78 |
|
@@ -80,42 +75,6 @@ def generate_summary_with_claude(transcript, prompt_text):
|
|
80 |
st.error(f"Ошибка при обращении к Claude: {e}")
|
81 |
return None
|
82 |
|
83 |
-
# Форматирование ответа
|
84 |
-
def format_answer(answer):
|
85 |
-
parts = re.split(r'(```.*?```)', answer, flags=re.DOTALL)
|
86 |
-
for part in parts:
|
87 |
-
if part.startswith('```') and part.endswith('```'):
|
88 |
-
language_and_code = part[3:-3].strip().split("\n", 1)
|
89 |
-
if len(language_and_code) == 2:
|
90 |
-
language, code = language_and_code
|
91 |
-
st.code(code, language=language)
|
92 |
-
else:
|
93 |
-
st.code(language_and_code[0])
|
94 |
-
else:
|
95 |
-
if re.search(r'(\d+\.\s+)', part):
|
96 |
-
part = format_as_numbered_list(part)
|
97 |
-
paragraphs = part.split('\n\n')
|
98 |
-
for paragraph in paragraphs:
|
99 |
-
if re.match(r'^\d+\.\s', paragraph):
|
100 |
-
st.markdown(paragraph)
|
101 |
-
elif re.match(r'^\*\s', paragraph):
|
102 |
-
st.markdown(paragraph)
|
103 |
-
else:
|
104 |
-
st.markdown(paragraph)
|
105 |
-
|
106 |
-
# Функция для нумерованных списков
|
107 |
-
def format_as_numbered_list(text):
|
108 |
-
cleaned_text = re.sub(r'\d+\n', '', text)
|
109 |
-
cleaned_text = re.sub(r'\d+\s+', '', cleaned_text)
|
110 |
-
sentences = cleaned_text.splitlines()
|
111 |
-
|
112 |
-
numbered_list = ""
|
113 |
-
for i, sentence in enumerate(sentences, start=1):
|
114 |
-
if sentence.strip():
|
115 |
-
numbered_list += f"{i}. {sentence.strip()}\n"
|
116 |
-
|
117 |
-
return numbered_list
|
118 |
-
|
119 |
# STREAMLIT
|
120 |
|
121 |
st.title("Смотрим лекции YouTube как Суперчеловек 💪")
|
|
|
68 |
}
|
69 |
]
|
70 |
)
|
|
|
|
|
|
|
|
|
|
|
71 |
|
72 |
return message.content[0].text
|
73 |
|
|
|
75 |
st.error(f"Ошибка при обращении к Claude: {e}")
|
76 |
return None
|
77 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
78 |
# STREAMLIT
|
79 |
|
80 |
st.title("Смотрим лекции YouTube как Суперчеловек 💪")
|