Spaces:
Sleeping
Sleeping
Upload folder using huggingface_hub
Browse files- 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)
|
| 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
|
| 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 |
-
|
| 64 |
""")
|
| 65 |
|
| 66 |
-
|
| 67 |
-
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
|
| 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 |
-
#
|
| 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="/")
|