civil_eng_tr / app.py
uisikdag's picture
Update app.py
2974d9f verified
import streamlit as st
import json
import requests
import os
API_TOKEN = os.environ.get("API_TOKEN")
API_URL = os.environ.get("API_URL")
headers = {"Authorization": f"Bearer {API_TOKEN}"}
def query(payload):
data = json.dumps(payload)
response = requests.request("POST", API_URL, headers=headers, data=data)
return json.loads(response.content.decode("utf-8"))
def analyze_txt(txt):
label_dict={'LABEL_0':'Geoteknik','LABEL_1':'Hidrolik','LABEL_2':'Malzeme','LABEL_3':'Ulaştırma','LABEL_4':'Yapı'}
data = query(txt)
result=data[0][0]['label']
decode_result=label_dict[result]
prob=data[0][0]['score']
result2=data[0][1]['label']
decode_result2=label_dict[result2]
prob2=data[0][1]['score']
strn='Best guess '+str(decode_result)+' ->confidence: '+str(round(prob,3))
strn2= 'Other guess '+str(decode_result2)+' ->confidence: '+str(round(prob2,3))
return strn,strn2
st.header('Find the Category of Turkish Civil Engineering Abstracts')
st.caption('classify->geoteknik,hidrolik,malzeme,ulaştırma,yapı')
txt = st.text_area('Abstract to analyze and predict(in Turkish)')
if st.button('Find the category'):
if txt != '':
txt1,txt2=analyze_txt(txt)
st.success(txt1, icon="✅")
st.info(txt2, icon="ℹ️")
else:
st.write('Please input text')