Spaces:
Runtime error
Runtime error
Commit
·
0ffbeb2
1
Parent(s):
3ac3978
try
Browse files- .idea/workspace.xml +2 -2
- src/hf.py +6 -2
- src/main.py +16 -9
.idea/workspace.xml
CHANGED
|
@@ -63,7 +63,7 @@
|
|
| 63 |
<recent name="D:\Development_Web\FullStackVercel\backend\src" />
|
| 64 |
</key>
|
| 65 |
</component>
|
| 66 |
-
<component name="RunManager" selected="Python.
|
| 67 |
<configuration name="cth" type="PythonConfigurationType" factoryName="Python" temporary="true" nameIsGenerated="true">
|
| 68 |
<module name="backend" />
|
| 69 |
<option name="ENV_FILES" value="" />
|
|
@@ -132,8 +132,8 @@
|
|
| 132 |
</configuration>
|
| 133 |
<recent_temporary>
|
| 134 |
<list>
|
| 135 |
-
<item itemvalue="Python.hf2" />
|
| 136 |
<item itemvalue="Python.hf" />
|
|
|
|
| 137 |
<item itemvalue="Python.cth" />
|
| 138 |
</list>
|
| 139 |
</recent_temporary>
|
|
|
|
| 63 |
<recent name="D:\Development_Web\FullStackVercel\backend\src" />
|
| 64 |
</key>
|
| 65 |
</component>
|
| 66 |
+
<component name="RunManager" selected="Python.hf">
|
| 67 |
<configuration name="cth" type="PythonConfigurationType" factoryName="Python" temporary="true" nameIsGenerated="true">
|
| 68 |
<module name="backend" />
|
| 69 |
<option name="ENV_FILES" value="" />
|
|
|
|
| 132 |
</configuration>
|
| 133 |
<recent_temporary>
|
| 134 |
<list>
|
|
|
|
| 135 |
<item itemvalue="Python.hf" />
|
| 136 |
+
<item itemvalue="Python.hf2" />
|
| 137 |
<item itemvalue="Python.cth" />
|
| 138 |
</list>
|
| 139 |
</recent_temporary>
|
src/hf.py
CHANGED
|
@@ -4,7 +4,7 @@ from transformers import BertTokenizer, BertForSequenceClassification,TextClassi
|
|
| 4 |
# Load tokenizer and model from the fine-tuned directory
|
| 5 |
model_path = './intent_classification/TinyBERT_106_V2' # can try other checkpoints
|
| 6 |
|
| 7 |
-
tokenizer = BertTokenizer.from_pretrained(
|
| 8 |
# model = BertForSequenceClassification.from_pretrained(model_path)
|
| 9 |
model = AutoModelForSequenceClassification.from_pretrained(model_path, local_files_only=True)
|
| 10 |
print(os.path.exists(model_path))
|
|
@@ -35,4 +35,8 @@ def generate_response(user_query):
|
|
| 35 |
return topic_label, score
|
| 36 |
|
| 37 |
|
| 38 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 4 |
# Load tokenizer and model from the fine-tuned directory
|
| 5 |
model_path = './intent_classification/TinyBERT_106_V2' # can try other checkpoints
|
| 6 |
|
| 7 |
+
tokenizer = BertTokenizer.from_pretrained(model_path)
|
| 8 |
# model = BertForSequenceClassification.from_pretrained(model_path)
|
| 9 |
model = AutoModelForSequenceClassification.from_pretrained(model_path, local_files_only=True)
|
| 10 |
print(os.path.exists(model_path))
|
|
|
|
| 35 |
return topic_label, score
|
| 36 |
|
| 37 |
|
| 38 |
+
def get_dir():
|
| 39 |
+
return os.getcwd()
|
| 40 |
+
|
| 41 |
+
print(generate_response("Procedure to withdraw"))
|
| 42 |
+
get_dir()
|
src/main.py
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
|
|
|
|
|
| 1 |
import uvicorn
|
| 2 |
from fastapi import FastAPI
|
| 3 |
from fastapi.middleware.cors import CORSMiddleware
|
| 4 |
-
from src.hf import generate_response
|
| 5 |
|
| 6 |
|
| 7 |
app = FastAPI()
|
|
@@ -19,19 +21,24 @@ app.add_middleware(
|
|
| 19 |
|
| 20 |
@app.get("/")
|
| 21 |
async def root():
|
| 22 |
-
|
|
|
|
| 23 |
|
| 24 |
@app.get("/book")
|
| 25 |
async def root():
|
| 26 |
return {"book_name": "Hikayat Naga Terbang"}
|
| 27 |
|
| 28 |
-
@app.post('/classify')
|
| 29 |
-
async def classify_text(question:str):
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 35 |
|
| 36 |
if __name__ == '__main__':
|
| 37 |
uvicorn.run("main:app", host="127.0.0.1", port=8000, reload=True)
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
|
| 3 |
import uvicorn
|
| 4 |
from fastapi import FastAPI
|
| 5 |
from fastapi.middleware.cors import CORSMiddleware
|
| 6 |
+
from src.hf import generate_response, get_dir
|
| 7 |
|
| 8 |
|
| 9 |
app = FastAPI()
|
|
|
|
| 21 |
|
| 22 |
@app.get("/")
|
| 23 |
async def root():
|
| 24 |
+
current_dir = os.getcwd()
|
| 25 |
+
return {"message": "Hello World", "dir": current_dir}
|
| 26 |
|
| 27 |
@app.get("/book")
|
| 28 |
async def root():
|
| 29 |
return {"book_name": "Hikayat Naga Terbang"}
|
| 30 |
|
| 31 |
+
# @app.post('/classify')
|
| 32 |
+
# async def classify_text(question:str):
|
| 33 |
+
# answer = generate_response(question)
|
| 34 |
+
# topic_label, score = answer
|
| 35 |
+
#
|
| 36 |
+
# return {"label": topic_label}
|
| 37 |
+
@app.get('/hf-dir')
|
| 38 |
+
def get_hf_dir():
|
| 39 |
+
return {
|
| 40 |
+
"hf_dir": get_dir()
|
| 41 |
+
}
|
| 42 |
|
| 43 |
if __name__ == '__main__':
|
| 44 |
uvicorn.run("main:app", host="127.0.0.1", port=8000, reload=True)
|