Spaces:
Running
Running
Commit
·
1f0f3cb
1
Parent(s):
a87d6f0
progress more (3.0)
Browse files
app.py
CHANGED
@@ -28,7 +28,14 @@ def translate_text(llm, text):
|
|
28 |
prompt = PromptTemplate(template=template, input_variables=["text"])
|
29 |
chain = prompt | llm | RunnablePassthrough()
|
30 |
response = chain.invoke({"text": text})
|
31 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
32 |
|
33 |
def get_mapped_sentiment(result):
|
34 |
label = result['label'].lower()
|
@@ -103,20 +110,22 @@ def estimate_impact(llm, news_text, entity):
|
|
103 |
Reasoning: [Your reasoning]
|
104 |
"""
|
105 |
prompt = PromptTemplate(template=template, input_variables=["entity", "news"])
|
106 |
-
chain = prompt | llm
|
107 |
response = chain.invoke({"entity": entity, "news": news_text})
|
108 |
|
109 |
impact = "Неопределенный эффект"
|
110 |
reasoning = "Не удалось получить обоснование"
|
111 |
|
112 |
-
|
113 |
-
|
114 |
-
|
115 |
-
|
116 |
-
|
117 |
-
|
118 |
-
|
119 |
-
|
|
|
|
|
120 |
|
121 |
return impact, reasoning
|
122 |
|
@@ -302,7 +311,7 @@ def main():
|
|
302 |
unsafe_allow_html=True
|
303 |
)
|
304 |
|
305 |
-
st.title("::: анализ мониторинга новостей СКАН-ИНТЕРФАКС (
|
306 |
|
307 |
if 'processed_df' not in st.session_state:
|
308 |
st.session_state.processed_df = None
|
|
|
28 |
prompt = PromptTemplate(template=template, input_variables=["text"])
|
29 |
chain = prompt | llm | RunnablePassthrough()
|
30 |
response = chain.invoke({"text": text})
|
31 |
+
|
32 |
+
# Handle different response types
|
33 |
+
if hasattr(response, 'content'): # If it's an AIMessage object
|
34 |
+
return response.content.strip()
|
35 |
+
elif isinstance(response, str): # If it's a string
|
36 |
+
return response.strip()
|
37 |
+
else:
|
38 |
+
return str(response).strip() # Convert any other type to string
|
39 |
|
40 |
def get_mapped_sentiment(result):
|
41 |
label = result['label'].lower()
|
|
|
110 |
Reasoning: [Your reasoning]
|
111 |
"""
|
112 |
prompt = PromptTemplate(template=template, input_variables=["entity", "news"])
|
113 |
+
chain = prompt | llm
|
114 |
response = chain.invoke({"entity": entity, "news": news_text})
|
115 |
|
116 |
impact = "Неопределенный эффект"
|
117 |
reasoning = "Не удалось получить обоснование"
|
118 |
|
119 |
+
# Extract content from response
|
120 |
+
response_text = response.content if hasattr(response, 'content') else str(response)
|
121 |
+
|
122 |
+
try:
|
123 |
+
if "Impact:" in response_text and "Reasoning:" in response_text:
|
124 |
+
impact_part, reasoning_part = response_text.split("Reasoning:")
|
125 |
+
impact = impact_part.split("Impact:")[1].strip()
|
126 |
+
reasoning = reasoning_part.strip()
|
127 |
+
except Exception as e:
|
128 |
+
st.error(f"Error parsing LLM response: {str(e)}")
|
129 |
|
130 |
return impact, reasoning
|
131 |
|
|
|
311 |
unsafe_allow_html=True
|
312 |
)
|
313 |
|
314 |
+
st.title("::: анализ мониторинга новостей СКАН-ИНТЕРФАКС (v.3.0):::")
|
315 |
|
316 |
if 'processed_df' not in st.session_state:
|
317 |
st.session_state.processed_df = None
|