hadangvu commited on
Commit
9ccf3de
Β·
verified Β·
1 Parent(s): 29e590e

Upload folder using huggingface_hub

Browse files
Files changed (1) hide show
  1. app/main.py +10 -19
app/main.py CHANGED
@@ -1,8 +1,5 @@
1
 
2
- import threading
3
- import uvicorn
4
  import gradio as gr
5
- import requests
6
  from fastapi import FastAPI, HTTPException
7
  from app.schemas import PredictRequest, PredictResponse
8
  from app import model as ml
@@ -10,14 +7,10 @@ from app import model as ml
10
  # ── FastAPI ──────────────────────────────────────────────
11
  app = FastAPI(
12
  title="PKD Financial Sentiment API",
13
- description=(
14
- "ALBERT student model trained via Patient Knowledge Distillation "
15
- "on scraped financial headlines. Outperforms FinBERT teacher on macro-F1."
16
- ),
17
  version="1.0.0",
18
  )
19
 
20
- @app.get("/")
21
  def root():
22
  return {
23
  "status": "ok",
@@ -47,7 +40,7 @@ LABEL_EMOJI = {
47
  def analyze(headline: str):
48
  if not headline.strip():
49
  return "Please enter a headline.", "", ""
50
- result = ml.predict(headline) # call directly, no HTTP hop needed
51
  return (
52
  LABEL_EMOJI[result["label"]],
53
  f"{result['confidence'] * 100:.1f}%",
@@ -56,20 +49,18 @@ def analyze(headline: str):
56
 
57
  with gr.Blocks(title="PKD Financial Sentiment") as demo:
58
  gr.Markdown("""
59
- # πŸ“ˆ PKD Financial Sentiment API
60
  ALBERT student model trained via **Patient Knowledge Distillation** on scraped
61
  financial headlines. Outperforms FinBERT teacher on macro-F1 at ~40% parameter count.
62
 
63
- **API endpoint:** `POST /predict` β€” see [/docs](/docs) for full spec.
64
  """)
65
 
66
- with gr.Row():
67
- text_input = gr.Textbox(
68
- label="Financial Headline",
69
- placeholder="e.g. Apple beats Q3 earnings expectations by wide margin",
70
- lines=2,
71
- scale=4,
72
- )
73
 
74
  analyze_btn = gr.Button("Analyze Sentiment", variant="primary")
75
 
@@ -95,5 +86,5 @@ with gr.Blocks(title="PKD Financial Sentiment") as demo:
95
  outputs=[label_out, confidence_out, latency_out],
96
  )
97
 
98
- # Mount Gradio onto FastAPI at root
99
  app = gr.mount_gradio_app(app, demo, path="/")
 
1
 
 
 
2
  import gradio as gr
 
3
  from fastapi import FastAPI, HTTPException
4
  from app.schemas import PredictRequest, PredictResponse
5
  from app import model as ml
 
7
  # ── FastAPI ──────────────────────────────────────────────
8
  app = FastAPI(
9
  title="PKD Financial Sentiment API",
 
 
 
 
10
  version="1.0.0",
11
  )
12
 
13
+ @app.get("/api")
14
  def root():
15
  return {
16
  "status": "ok",
 
40
  def analyze(headline: str):
41
  if not headline.strip():
42
  return "Please enter a headline.", "", ""
43
+ result = ml.predict(headline)
44
  return (
45
  LABEL_EMOJI[result["label"]],
46
  f"{result['confidence'] * 100:.1f}%",
 
49
 
50
  with gr.Blocks(title="PKD Financial Sentiment") as demo:
51
  gr.Markdown("""
52
+ # πŸ“ˆ PKD Financial Sentiment
53
  ALBERT student model trained via **Patient Knowledge Distillation** on scraped
54
  financial headlines. Outperforms FinBERT teacher on macro-F1 at ~40% parameter count.
55
 
56
+ API endpoint: `POST /predict` β€” see [/docs](/docs) for full spec.
57
  """)
58
 
59
+ text_input = gr.Textbox(
60
+ label="Financial Headline",
61
+ placeholder="e.g. Apple beats Q3 earnings expectations by wide margin",
62
+ lines=2,
63
+ )
 
 
64
 
65
  analyze_btn = gr.Button("Analyze Sentiment", variant="primary")
66
 
 
86
  outputs=[label_out, confidence_out, latency_out],
87
  )
88
 
89
+ # Gradio takes over "/" β€” FastAPI routes still work at /predict, /docs, /health
90
  app = gr.mount_gradio_app(app, demo, path="/")