harry-stark commited on
Commit
bb514b9
1 Parent(s): 332e4a1

Refactor:examples.json and utils.py

Browse files
Files changed (3) hide show
  1. app.py +8 -7
  2. examples.json +1 -1
  3. utils.py +9 -1
app.py CHANGED
@@ -1,20 +1,21 @@
1
- from os import write
2
- from typing import Sequence
3
  import streamlit as st
4
  from hf_model import classifier_zero,load_model
5
- from utils import plot_result
6
  import json
 
7
  classifier=load_model()
8
- with open("examples.json") as f:
9
- data=json.load(f)
 
 
10
 
11
  if __name__ == '__main__':
12
  st.header("Zero Shot Classification")
13
  st.write("This app allows you to classify any text into any categories you are interested in.")
14
 
15
  with st.form(key='my_form'):
16
- text_input = st.text_area("Input Text",data['text'])
17
- labels = st.text_input('Possible topics (separated by `,`)',data["labels"], max_chars=1000)
18
  labels = list(set([x.strip() for x in labels.strip().split(',') if len(x.strip()) > 0]))
19
  radio = st.radio("Select Multiclass",('Only one topic can be corect at a time','Multiple topics can be correct at a time'),)
20
  multi_class= True if radio=="Multiple topics can be correct at a time" else False
 
 
 
1
  import streamlit as st
2
  from hf_model import classifier_zero,load_model
3
+ from utils import plot_result,examples_load
4
  import json
5
+
6
  classifier=load_model()
7
+ ex_text,ex_labels=examples_load()
8
+
9
+ # with open("examples.json") as f:
10
+ # data=json.load(f)
11
 
12
  if __name__ == '__main__':
13
  st.header("Zero Shot Classification")
14
  st.write("This app allows you to classify any text into any categories you are interested in.")
15
 
16
  with st.form(key='my_form'):
17
+ text_input = st.text_area("Input Text",ex_text)
18
+ labels = st.text_input('Possible topics (separated by `,`)',ex_labels, max_chars=1000)
19
  labels = list(set([x.strip() for x in labels.strip().split(',') if len(x.strip()) > 0]))
20
  radio = st.radio("Select Multiclass",('Only one topic can be corect at a time','Multiple topics can be correct at a time'),)
21
  multi_class= True if radio=="Multiple topics can be correct at a time" else False
examples.json CHANGED
@@ -1,4 +1,4 @@
1
  {
2
  "text":"The Democratic president had just signed into law the most significant infrastructure package in generations. And he had done it by bringing Democrats and Republicans together.",
3
- "labels":["Economy", "Politics", "Environment", "Entertainment"]
4
  }
 
1
  {
2
  "text":"The Democratic president had just signed into law the most significant infrastructure package in generations. And he had done it by bringing Democrats and Republicans together.",
3
+ "labels":"Economy,Politics,Environment,Entertainment"
4
  }
utils.py CHANGED
@@ -1,6 +1,8 @@
1
  import streamlit as st
2
  import numpy as np
3
  import plotly.express as px
 
 
4
  def plot_result(top_topics, scores):
5
  top_topics = np.array(top_topics)
6
  scores = np.array(scores)
@@ -14,4 +16,10 @@ def plot_result(top_topics, scores):
14
  color_continuous_scale='GnBu')
15
  fig.update(layout_coloraxis_showscale=False)
16
  fig.update_traces(texttemplate='%{text:0.1f}%', textposition='outside')
17
- st.plotly_chart(fig)
 
 
 
 
 
 
 
1
  import streamlit as st
2
  import numpy as np
3
  import plotly.express as px
4
+ import json
5
+
6
  def plot_result(top_topics, scores):
7
  top_topics = np.array(top_topics)
8
  scores = np.array(scores)
 
16
  color_continuous_scale='GnBu')
17
  fig.update(layout_coloraxis_showscale=False)
18
  fig.update_traces(texttemplate='%{text:0.1f}%', textposition='outside')
19
+ st.plotly_chart(fig)
20
+
21
+ def examples_load():
22
+ with open("examples.json") as f:
23
+ data=json.load(f)
24
+
25
+ return data['text'],data['labels']