Spaces:
Sleeping
Sleeping
remove pydantic and update api for base
Browse files- main.py +5 -5
- static/index.html +2 -2
- static/script.js +5 -5
- static/style.css +0 -6
main.py
CHANGED
@@ -1,7 +1,7 @@
|
|
1 |
from fastapi import FastAPI
|
2 |
from fastapi.staticfiles import StaticFiles
|
3 |
from fastapi.responses import FileResponse
|
4 |
-
from pydantic import BaseModel
|
5 |
import spacy
|
6 |
from spacy.matcher import Matcher
|
7 |
|
@@ -10,14 +10,14 @@ nlp = spacy.load("en_core_web_sm")
|
|
10 |
matcher = Matcher(nlp.vocab)
|
11 |
|
12 |
# Define a Pydantic model for the request body
|
13 |
-
class TextInput(BaseModel):
|
14 |
-
|
15 |
|
16 |
@app.get("/score_text")
|
17 |
-
def score_text(text_input
|
18 |
"""Endpoint to score text for uncertain statements using spaCy Matcher."""
|
19 |
# Load the text into spaCy's nlp object
|
20 |
-
doc = nlp(text_input
|
21 |
|
22 |
# Define spaCy Matcher patterns for uncertain statements
|
23 |
pattern1 = [{"IS_ALPHA": True, "OP": "?"}, {"ORTH": "may"}, {"IS_ALPHA": True, "OP": "?"}]
|
|
|
1 |
from fastapi import FastAPI
|
2 |
from fastapi.staticfiles import StaticFiles
|
3 |
from fastapi.responses import FileResponse
|
4 |
+
# from pydantic import BaseModel
|
5 |
import spacy
|
6 |
from spacy.matcher import Matcher
|
7 |
|
|
|
10 |
matcher = Matcher(nlp.vocab)
|
11 |
|
12 |
# Define a Pydantic model for the request body
|
13 |
+
# class TextInput(BaseModel):
|
14 |
+
# text: str
|
15 |
|
16 |
@app.get("/score_text")
|
17 |
+
def score_text(text_input):
|
18 |
"""Endpoint to score text for uncertain statements using spaCy Matcher."""
|
19 |
# Load the text into spaCy's nlp object
|
20 |
+
doc = nlp(text_input)
|
21 |
|
22 |
# Define spaCy Matcher patterns for uncertain statements
|
23 |
pattern1 = [{"IS_ALPHA": True, "OP": "?"}, {"ORTH": "may"}, {"IS_ALPHA": True, "OP": "?"}]
|
static/index.html
CHANGED
@@ -12,11 +12,11 @@
|
|
12 |
<section id="text-spacy">
|
13 |
<h1>Uncertainty statements</h1>
|
14 |
<form class="text-spacy-form">
|
15 |
-
<label for="text-spacy-input">
|
16 |
<input
|
17 |
id="text-spacy-input"
|
18 |
type="text"
|
19 |
-
value="
|
20 |
/>
|
21 |
<button id="text-spacy-submit">Submit</button>
|
22 |
<p class="text-spacy-output"></p>
|
|
|
12 |
<section id="text-spacy">
|
13 |
<h1>Uncertainty statements</h1>
|
14 |
<form class="text-spacy-form">
|
15 |
+
<label for="text-spacy-input">Input text</label>
|
16 |
<input
|
17 |
id="text-spacy-input"
|
18 |
type="text"
|
19 |
+
value="Dear shareholders, we may face challenges in the coming quarter due to uncertain market conditions. Our revenues might be impacted by factors beyond our control, such as economic fluctuations and regulatory changes. However, we remain committed to our long-term strategy and will continue to explore new opportunities. Thank you for your continued support."
|
20 |
/>
|
21 |
<button id="text-spacy-submit">Submit</button>
|
22 |
<p class="text-spacy-output"></p>
|
static/script.js
CHANGED
@@ -1,13 +1,13 @@
|
|
1 |
-
const
|
2 |
|
3 |
const translateText = async (text) => {
|
4 |
-
const inferResponse = await fetch(`score_text?
|
5 |
const inferJson = await inferResponse.json();
|
6 |
-
|
7 |
-
return
|
8 |
};
|
9 |
|
10 |
-
|
11 |
event.preventDefault();
|
12 |
|
13 |
const textSpacyInput = document.getElementById('text-spacy-input');
|
|
|
1 |
+
const textSpacyForm = document.querySelector('.text-spacy-form');
|
2 |
|
3 |
const translateText = async (text) => {
|
4 |
+
const inferResponse = await fetch(`score_text?text_input=${text}`);
|
5 |
const inferJson = await inferResponse.json();
|
6 |
+
var jsonStr = JSON.stringify(inferJson);
|
7 |
+
return jsonStr;
|
8 |
};
|
9 |
|
10 |
+
textSpacyForm.addEventListener('submit', async (event) => {
|
11 |
event.preventDefault();
|
12 |
|
13 |
const textSpacyInput = document.getElementById('text-spacy-input');
|
static/style.css
CHANGED
@@ -37,9 +37,3 @@ body {
|
|
37 |
button {
|
38 |
cursor: pointer;
|
39 |
}
|
40 |
-
|
41 |
-
.text-spacy-output {
|
42 |
-
min-height: 1.2rem;
|
43 |
-
margin: 1rem;
|
44 |
-
border: 0.5px solid grey;
|
45 |
-
}
|
|
|
37 |
button {
|
38 |
cursor: pointer;
|
39 |
}
|
|
|
|
|
|
|
|
|
|
|
|