Jose Salazar commited on
Commit
8ed7e32
·
1 Parent(s): 714ef9d

Modificaciones menores en archivos del pipeline de ia

Browse files
backend/src/signals/finnhub.client.js CHANGED
@@ -2,8 +2,8 @@
2
  * Servicio de integracion con Finnhub REST API.
3
  *
4
  * Responsabilidades:
5
- * - fetchFinancialNews(count) → obtiene titulares de noticias financieras.
6
- * - filterNewsByRelevance(articles, question) → filtra por keywords del mercado.
7
  *
8
  * Restricciones:
9
  * - Free tier: maximo 60 llamadas/minuto.
@@ -14,27 +14,3 @@
14
  * - aiPipeline.js → fase 1 de filtrado de noticias.
15
  */
16
 
17
- import { httpGet } from '../utils/httpClient.js';
18
- import { config } from '../config.js';
19
-
20
- export async function fetchFinancialNews(count = 30) {
21
- if (!config.FINNHUB_API_KEY) return [];
22
- const url = `https://finnhub.io/api/v1/news?category=general&token=${config.FINNHUB_API_KEY}`;
23
- const articles = await httpGet(url);
24
- return articles.slice(0, count).map((a) => ({
25
- headline: a.headline ?? '',
26
- summary: a.summary ?? '',
27
- }));
28
- }
29
-
30
- export function filterNewsByRelevance(articles, question) {
31
- const keywords = question
32
- .toLowerCase()
33
- .split(/\W+/)
34
- .filter((w) => w.length > 4);
35
- if (keywords.length === 0) return articles;
36
- return articles.filter((a) => {
37
- const text = `${a.headline} ${a.summary}`.toLowerCase();
38
- return keywords.some((kw) => text.includes(kw));
39
- });
40
- }
 
2
  * Servicio de integracion con Finnhub REST API.
3
  *
4
  * Responsabilidades:
5
+ * - Obtener titulares de noticias financieras.
6
+ * - Filtrar por keywords del mercado.
7
  *
8
  * Restricciones:
9
  * - Free tier: maximo 60 llamadas/minuto.
 
14
  * - aiPipeline.js → fase 1 de filtrado de noticias.
15
  */
16
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
spaces/modernfinbert/app.py CHANGED
@@ -2,9 +2,6 @@ import gradio as gr
2
  import spaces
3
  from transformers import pipeline
4
 
5
- # Load model on CUDA at module level.
6
- # Outside @spaces.GPU a PyTorch CUDA emulation is active,
7
- # so this works even when no real GPU is allocated yet.
8
  print("Loading tabularisai/ModernFinBERT on cuda...")
9
  classifier = pipeline(
10
  "text-classification",
@@ -23,15 +20,12 @@ def predict_sentiment(text_block):
23
  if not text_block:
24
  return []
25
 
26
- # Split by newline, strip, drop empties
27
  texts = [t.strip() for t in text_block.splitlines() if t.strip()]
28
  if not texts:
29
  return []
30
 
31
- # Batch inference
32
  raw_results = classifier(texts, batch_size=32)
33
 
34
- # Normalise output
35
  results = [
36
  {"label": r["label"], "score": float(r["score"])}
37
  for r in raw_results
 
2
  import spaces
3
  from transformers import pipeline
4
 
 
 
 
5
  print("Loading tabularisai/ModernFinBERT on cuda...")
6
  classifier = pipeline(
7
  "text-classification",
 
20
  if not text_block:
21
  return []
22
 
 
23
  texts = [t.strip() for t in text_block.splitlines() if t.strip()]
24
  if not texts:
25
  return []
26
 
 
27
  raw_results = classifier(texts, batch_size=32)
28
 
 
29
  results = [
30
  {"label": r["label"], "score": float(r["score"])}
31
  for r in raw_results
spaces/qwen3-8b/app.py CHANGED
@@ -7,8 +7,7 @@ from transformers import AutoModelForCausalLM, AutoTokenizer
7
  MODEL_ID = "Qwen/Qwen2.5-7B-Instruct"
8
 
9
  print(f"Loading {MODEL_ID}...")
10
- # Load model on CUDA at module level.
11
- # Outside @spaces.GPU a PyTorch CUDA emulation is active.
12
  tokenizer = AutoTokenizer.from_pretrained(MODEL_ID)
13
  model = AutoModelForCausalLM.from_pretrained(
14
  MODEL_ID,
@@ -31,13 +30,12 @@ SYSTEM_PROMPT = (
31
 
32
  def extract_json(text: str) -> dict:
33
  """Try to extract a JSON object from the model output."""
34
- # Try direct JSON parse first
35
  try:
36
  return json.loads(text)
37
  except json.JSONDecodeError:
38
  pass
39
 
40
- # Look for JSON block inside markdown or raw text
41
  match = re.search(r"\{.*\}", text, re.DOTALL)
42
  if match:
43
  try:
 
7
  MODEL_ID = "Qwen/Qwen2.5-7B-Instruct"
8
 
9
  print(f"Loading {MODEL_ID}...")
10
+
 
11
  tokenizer = AutoTokenizer.from_pretrained(MODEL_ID)
12
  model = AutoModelForCausalLM.from_pretrained(
13
  MODEL_ID,
 
30
 
31
  def extract_json(text: str) -> dict:
32
  """Try to extract a JSON object from the model output."""
33
+
34
  try:
35
  return json.loads(text)
36
  except json.JSONDecodeError:
37
  pass
38
 
 
39
  match = re.search(r"\{.*\}", text, re.DOTALL)
40
  if match:
41
  try: