Update main.py
Browse files
main.py
CHANGED
@@ -6,6 +6,9 @@ from huggingface_hub import InferenceClient
|
|
6 |
import random
|
7 |
from json_repair import repair_json
|
8 |
import nltk
|
|
|
|
|
|
|
9 |
|
10 |
app = FastAPI()
|
11 |
|
@@ -25,6 +28,10 @@ class InputData(BaseModel):
|
|
25 |
json_prompt: str
|
26 |
history: str = ""
|
27 |
|
|
|
|
|
|
|
|
|
28 |
@app.post("/generate-response/")
|
29 |
async def generate_response(data: InputData) -> Dict[str, Any]:
|
30 |
client = InferenceClient(model=data.model, token=HF_TOKEN)
|
@@ -92,4 +99,30 @@ async def generate_response(data: InputData) -> Dict[str, Any]:
|
|
92 |
|
93 |
except Exception as e:
|
94 |
print(f"Model {data.model} failed with error: {e}")
|
95 |
-
raise HTTPException(status_code=500, detail=f"Model {data.model} failed to generate response")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
6 |
import random
|
7 |
from json_repair import repair_json
|
8 |
import nltk
|
9 |
+
import json
|
10 |
+
import re
|
11 |
+
from word_forms.word_forms import get_word_forms
|
12 |
|
13 |
app = FastAPI()
|
14 |
|
|
|
28 |
json_prompt: str
|
29 |
history: str = ""
|
30 |
|
31 |
+
class WordCheckData(BaseModel):
|
32 |
+
string: str
|
33 |
+
word: str
|
34 |
+
|
35 |
@app.post("/generate-response/")
|
36 |
async def generate_response(data: InputData) -> Dict[str, Any]:
|
37 |
client = InferenceClient(model=data.model, token=HF_TOKEN)
|
|
|
99 |
|
100 |
except Exception as e:
|
101 |
print(f"Model {data.model} failed with error: {e}")
|
102 |
+
raise HTTPException(status_code=500, detail=f"Model {data.model} failed to generate response")
|
103 |
+
|
104 |
+
@app.post("/check-word/")
|
105 |
+
async def check_word(data: WordCheckData) -> Dict[str, Any]:
|
106 |
+
input_string = data.string.lower()
|
107 |
+
word = data.word.lower()
|
108 |
+
|
109 |
+
forms = get_word_forms(word)
|
110 |
+
|
111 |
+
all_forms = set()
|
112 |
+
for words in forms.values():
|
113 |
+
all_forms.update(words)
|
114 |
+
|
115 |
+
# Split the input string into words using regular expression to handle spaces and punctuation
|
116 |
+
words_in_string = re.findall(r'\b\w+\b', input_string)
|
117 |
+
|
118 |
+
found = False
|
119 |
+
for word_in_string in words_in_string:
|
120 |
+
if word_in_string in all_forms:
|
121 |
+
found = True
|
122 |
+
break
|
123 |
+
|
124 |
+
result = {
|
125 |
+
"found": found
|
126 |
+
}
|
127 |
+
|
128 |
+
return result
|