Spaces:
Sleeping
Sleeping
Commit
·
a6e9232
1
Parent(s):
4fa1abd
progress more (3.4)
Browse files- app.py +34 -15
- requirements.txt +2 -1
app.py
CHANGED
|
@@ -7,17 +7,17 @@ import io
|
|
| 7 |
from rapidfuzz import fuzz
|
| 8 |
import os
|
| 9 |
from openpyxl import load_workbook
|
| 10 |
-
from langchain_community.chat_models import ChatOpenAI
|
| 11 |
from langchain.prompts import PromptTemplate
|
| 12 |
from langchain_core.runnables import RunnablePassthrough
|
| 13 |
from transformers import pipeline
|
| 14 |
from io import StringIO, BytesIO
|
| 15 |
import sys
|
| 16 |
import contextlib
|
|
|
|
|
|
|
|
|
|
| 17 |
|
| 18 |
|
| 19 |
-
from fpdf import FPDF
|
| 20 |
-
|
| 21 |
|
| 22 |
def display_sentiment_results(row, sentiment, impact=None, reasoning=None):
|
| 23 |
if sentiment == "Negative":
|
|
@@ -46,7 +46,7 @@ def display_sentiment_results(row, sentiment, impact=None, reasoning=None):
|
|
| 46 |
st.write("---")
|
| 47 |
|
| 48 |
|
| 49 |
-
|
| 50 |
|
| 51 |
class StreamlitCapture:
|
| 52 |
def __init__(self):
|
|
@@ -56,17 +56,36 @@ class StreamlitCapture:
|
|
| 56 |
self.texts.append(str(text))
|
| 57 |
|
| 58 |
def save_streamlit_output_to_pdf(texts):
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 63 |
|
| 64 |
-
|
| 65 |
-
|
| 66 |
-
clean_text = text.encode('latin-1', errors='replace').decode('latin-1')
|
| 67 |
-
pdf.multi_cell(0, 10, clean_text)
|
| 68 |
|
| 69 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 70 |
|
| 71 |
|
| 72 |
# Initialize sentiment analyzers
|
|
@@ -139,7 +158,7 @@ def init_langchain_llm():
|
|
| 139 |
llm = ChatOpenAI(
|
| 140 |
base_url="https://api.groq.com/openai/v1",
|
| 141 |
model="llama-3.1-70b-versatile",
|
| 142 |
-
|
| 143 |
temperature=0.0
|
| 144 |
)
|
| 145 |
return llm
|
|
@@ -401,7 +420,7 @@ def main():
|
|
| 401 |
unsafe_allow_html=True
|
| 402 |
)
|
| 403 |
|
| 404 |
-
st.title("::: анализ мониторинга новостей СКАН-ИНТЕРФАКС (v.3.
|
| 405 |
|
| 406 |
if 'processed_df' not in st.session_state:
|
| 407 |
st.session_state.processed_df = None
|
|
|
|
| 7 |
from rapidfuzz import fuzz
|
| 8 |
import os
|
| 9 |
from openpyxl import load_workbook
|
|
|
|
| 10 |
from langchain.prompts import PromptTemplate
|
| 11 |
from langchain_core.runnables import RunnablePassthrough
|
| 12 |
from transformers import pipeline
|
| 13 |
from io import StringIO, BytesIO
|
| 14 |
import sys
|
| 15 |
import contextlib
|
| 16 |
+
from langchain_openai import ChatOpenAI # Updated import
|
| 17 |
+
import pdfkit
|
| 18 |
+
from jinja2 import Template
|
| 19 |
|
| 20 |
|
|
|
|
|
|
|
| 21 |
|
| 22 |
def display_sentiment_results(row, sentiment, impact=None, reasoning=None):
|
| 23 |
if sentiment == "Negative":
|
|
|
|
| 46 |
st.write("---")
|
| 47 |
|
| 48 |
|
| 49 |
+
|
| 50 |
|
| 51 |
class StreamlitCapture:
|
| 52 |
def __init__(self):
|
|
|
|
| 56 |
self.texts.append(str(text))
|
| 57 |
|
| 58 |
def save_streamlit_output_to_pdf(texts):
|
| 59 |
+
# Create HTML content
|
| 60 |
+
html_content = """
|
| 61 |
+
<html>
|
| 62 |
+
<head>
|
| 63 |
+
<meta charset="UTF-8">
|
| 64 |
+
<style>
|
| 65 |
+
body { font-family: Arial, sans-serif; }
|
| 66 |
+
.content { margin: 20px; }
|
| 67 |
+
</style>
|
| 68 |
+
</head>
|
| 69 |
+
<body>
|
| 70 |
+
<div class="content">
|
| 71 |
+
{% for text in texts %}
|
| 72 |
+
<p>{{ text }}</p>
|
| 73 |
+
{% endfor %}
|
| 74 |
+
</div>
|
| 75 |
+
</body>
|
| 76 |
+
</html>
|
| 77 |
+
"""
|
| 78 |
|
| 79 |
+
template = Template(html_content)
|
| 80 |
+
rendered_html = template.render(texts=texts)
|
|
|
|
|
|
|
| 81 |
|
| 82 |
+
try:
|
| 83 |
+
# Convert HTML to PDF
|
| 84 |
+
pdfkit.from_string(rendered_html, 'result.pdf')
|
| 85 |
+
st.success("PDF файл 'result.pdf' успешно создан")
|
| 86 |
+
except Exception as e:
|
| 87 |
+
st.error(f"Ошибка при создании PDF: {str(e)}")
|
| 88 |
+
st.warning("PDF generation requires wkhtmltopdf to be installed")
|
| 89 |
|
| 90 |
|
| 91 |
# Initialize sentiment analyzers
|
|
|
|
| 158 |
llm = ChatOpenAI(
|
| 159 |
base_url="https://api.groq.com/openai/v1",
|
| 160 |
model="llama-3.1-70b-versatile",
|
| 161 |
+
openai_api_key=groq_api_key, # Updated parameter name
|
| 162 |
temperature=0.0
|
| 163 |
)
|
| 164 |
return llm
|
|
|
|
| 420 |
unsafe_allow_html=True
|
| 421 |
)
|
| 422 |
|
| 423 |
+
st.title("::: анализ мониторинга новостей СКАН-ИНТЕРФАКС (v.3.4):::")
|
| 424 |
|
| 425 |
if 'processed_df' not in st.session_state:
|
| 426 |
st.session_state.processed_df = None
|
requirements.txt
CHANGED
|
@@ -16,4 +16,5 @@ huggingface_hub
|
|
| 16 |
accelerate>=0.26.0
|
| 17 |
openai
|
| 18 |
wordcloud
|
| 19 |
-
|
|
|
|
|
|
| 16 |
accelerate>=0.26.0
|
| 17 |
openai
|
| 18 |
wordcloud
|
| 19 |
+
pdfkit
|
| 20 |
+
Jinja2==3.1.2
|