pentarosarium commited on
Commit
c45cef9
·
1 Parent(s): e0f842d

progress more 50

Browse files
Files changed (1) hide show
  1. app.py +17 -8
app.py CHANGED
@@ -46,7 +46,7 @@ def init_langchain_llm():
46
 
47
  def llama_wrapper(prompt):
48
  messages = [
49
- {"role": "system", "content": "You are a helpful AI assistant that analyzes news and estimates their impact."},
50
  {"role": "user", "content": prompt},
51
  ]
52
  result = pipeline(messages, max_new_tokens=256)
@@ -55,24 +55,32 @@ def init_langchain_llm():
55
  llm = HuggingFacePipeline(pipeline=llama_wrapper)
56
  return llm
57
 
58
- def estimate_impact(llm, news_text):
59
  template = """
60
- Analyze the following news piece and estimate its monetary impact in Russian rubles for the next 6 months.
61
- If a monetary estimate is not possible, categorize the impact as "Значительный", "Незначительный", or "Неопределенный".
 
 
 
 
 
 
 
62
  Also provide a short reasoning (max 100 words) for your assessment.
63
 
 
64
  News: {news}
65
 
66
  Your response should be in the following format:
67
  Estimated Impact: [Your estimate or category]
68
  Reasoning: [Your reasoning]
69
  """
70
- prompt = PromptTemplate(template=template, input_variables=["news"])
71
  chain = LLMChain(llm=llm, prompt=prompt)
72
- response = chain.run(news=news_text)
73
 
74
  # Parse the response
75
- impact = "Неопределенный"
76
  reasoning = "Не удалось получить обоснование"
77
 
78
  if "Estimated Impact:" in response and "Reasoning:" in response:
@@ -100,6 +108,7 @@ def process_file_with_llm(df, llm):
100
  df.at[index, 'LLM_Impact'] = impact
101
  df.at[index, 'LLM_Reasoning'] = reasoning
102
  # Display each LLM response
 
103
  st.write(f"Новость: {row['Заголовок']}")
104
  st.write(f"Эффект: {impact}")
105
  st.write(f"Обоснование: {reasoning}")
@@ -418,7 +427,7 @@ def create_output_file(df, uploaded_file, analysis_df):
418
  return output
419
 
420
  def main():
421
- st.title("... приступим к анализу... версия 49")
422
 
423
  # Initialize session state
424
  if 'processed_df' not in st.session_state:
 
46
 
47
  def llama_wrapper(prompt):
48
  messages = [
49
+ {"role": "system", "content": "You are an experienced credit analyst that analyzes news and estimates their short-term or mid-term impact on profitability or risk of loss of the entity present in the news."},
50
  {"role": "user", "content": prompt},
51
  ]
52
  result = pipeline(messages, max_new_tokens=256)
 
55
  llm = HuggingFacePipeline(pipeline=llama_wrapper)
56
  return llm
57
 
58
+ def estimate_impact(llm, news_text, entity):
59
  template = """
60
+ Analyze the following news piece about the entity "{entity}" and estimate its monetary impact in Russian rubles for this entity in the next 6 months. You should estimate the risk of loss or probability of profit.
61
+
62
+ If a precise monetary estimate is not possible, categorize the impact as one of the following:
63
+ 1. "Значительный риск убытков" (Significant risk of loss)
64
+ 2. "Умеренный риск убытков" (Moderate risk of loss)
65
+ 3. "Незначительный риск убытков" (Minor risk of loss)
66
+ 4. "Вероятность прибыли" (Probability of profit)
67
+ 5. "Неопределенный эффект" (Uncertain effect)
68
+
69
  Also provide a short reasoning (max 100 words) for your assessment.
70
 
71
+ Entity: {entity}
72
  News: {news}
73
 
74
  Your response should be in the following format:
75
  Estimated Impact: [Your estimate or category]
76
  Reasoning: [Your reasoning]
77
  """
78
+ prompt = PromptTemplate(template=template, input_variables=["entity", "news"])
79
  chain = LLMChain(llm=llm, prompt=prompt)
80
+ response = chain.run(entity=entity, news=news_text)
81
 
82
  # Parse the response
83
+ impact = "Неопределенный эффект"
84
  reasoning = "Не удалось получить обоснование"
85
 
86
  if "Estimated Impact:" in response and "Reasoning:" in response:
 
108
  df.at[index, 'LLM_Impact'] = impact
109
  df.at[index, 'LLM_Reasoning'] = reasoning
110
  # Display each LLM response
111
+ t.write(f"Объект: {row['Объект']}")
112
  st.write(f"Новость: {row['Заголовок']}")
113
  st.write(f"Эффект: {impact}")
114
  st.write(f"Обоснование: {reasoning}")
 
427
  return output
428
 
429
  def main():
430
+ st.title("... приступим к анализу... версия 50")
431
 
432
  # Initialize session state
433
  if 'processed_df' not in st.session_state: