Upload app.py
Browse files
app.py
ADDED
@@ -0,0 +1,42 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# -*- coding: utf-8 -*-
|
2 |
+
"""app.ipynb
|
3 |
+
|
4 |
+
Automatically generated by Colab.
|
5 |
+
|
6 |
+
Original file is located at
|
7 |
+
https://colab.research.google.com/drive/1ewSnt_PQx8cX9GC2XAguVNesbn8MM3tA
|
8 |
+
"""
|
9 |
+
|
10 |
+
|
11 |
+
|
12 |
+
from fastapi import FastAPI
|
13 |
+
from pydantic import BaseModel
|
14 |
+
from transformers import RobertaTokenizer, RobertaForMaskedLM, pipeline
|
15 |
+
|
16 |
+
app = FastAPI()
|
17 |
+
|
18 |
+
|
19 |
+
model_name = "web3se/SmartBERT-v3"
|
20 |
+
tokenizer = RobertaTokenizer.from_pretrained(model_name)
|
21 |
+
model = RobertaForMaskedLM.from_pretrained(model_name)
|
22 |
+
|
23 |
+
# Create fill-mask pipeline
|
24 |
+
fill_mask = pipeline('fill-mask', model=model, tokenizer=tokenizer)
|
25 |
+
|
26 |
+
# Define request body
|
27 |
+
class ContractRequest(BaseModel):
|
28 |
+
contract_code: str
|
29 |
+
|
30 |
+
@app.post("/analyze/")
|
31 |
+
async def analyze_contract(request: ContractRequest):
|
32 |
+
# Use fill-mask on contract code
|
33 |
+
outputs = fill_mask(request.contract_code)
|
34 |
+
|
35 |
+
return {"predictions": outputs} # Returns top masked token predictions
|
36 |
+
|
37 |
+
|
38 |
+
# Run API on Hugging Face Spaces
|
39 |
+
if __name__ == "__main__":
|
40 |
+
import uvicorn
|
41 |
+
uvicorn.run(app, host="0.0.0.0", port=7860)
|
42 |
+
|