maslionok commited on
Commit
00f4271
·
1 Parent(s): 7b1cc64

adding all files

Browse files
Files changed (3) hide show
  1. Dockerfile +20 -0
  2. app.py +62 -0
  3. requirements.txt +2 -0
Dockerfile ADDED
@@ -0,0 +1,20 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ FROM python:3.9-slim
2
+
3
+ WORKDIR /code
4
+
5
+ # Install git (required for pip installing from github)
6
+ RUN apt-get update && apt-get install -y git \
7
+ && rm -rf /var/lib/apt/lists/*
8
+
9
+ # Copy requirements and install dependencies
10
+ COPY requirements.txt .
11
+ RUN pip install --no-cache-dir --upgrade -r requirements.txt
12
+
13
+ # Copy the rest of the application code
14
+ COPY . .
15
+
16
+ # Expose the port for Streamlit
17
+ EXPOSE 7860
18
+
19
+ # Command to run the app
20
+ CMD ["streamlit", "run", "app.py", "--server.address=0.0.0.0", "--server.port=7860"]
app.py ADDED
@@ -0,0 +1,62 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import json
3
+ # Importing directly from the installed package as requested
4
+ from impresso_pipelines.oneclassadclassifier import AdClassificationPipeline
5
+
6
+ # --- PAGE CONFIG ---
7
+ st.set_page_config(page_title="Impresso Ad Classifier", layout="centered")
8
+
9
+ st.title("📰 Impresso Ad Classifier")
10
+ st.markdown("Enter text below to classify it as an Advertisement or Non-Advertisement using the `ad_model_pipeline`.")
11
+
12
+ # --- LOAD PIPELINE ---
13
+ @st.cache_resource
14
+ def load_pipeline():
15
+ # Initialize with diagnostics=True to get all parameters
16
+ return AdClassificationPipeline(diagnostics=True)
17
+
18
+ try:
19
+ with st.spinner("Loading pipeline from GitHub..."):
20
+ pipeline = load_pipeline()
21
+ except Exception as e:
22
+ st.error(f"Failed to load pipeline: {e}")
23
+ st.stop()
24
+
25
+ # --- USER INTERFACE ---
26
+ text_input = st.text_area("Input Text", height=200, placeholder="Paste historical text here...")
27
+
28
+ if st.button("Classify", type="primary"):
29
+ if text_input.strip():
30
+ with st.spinner("Running classification..."):
31
+ try:
32
+ # Running the pipeline exactly as shown in your snippet
33
+ results = pipeline(text_input, precision=2)
34
+
35
+ # Handle if result is a list (batch) or dict (single)
36
+ # The pipeline usually returns a list for text input, so we take the first item if so
37
+ if isinstance(results, list) and len(results) > 0:
38
+ main_result = results[0]
39
+ else:
40
+ main_result = results
41
+
42
+ # --- DISPLAY RESULTS ---
43
+ st.divider()
44
+
45
+ # 1. Visual Header
46
+ result_type = main_result.get('type', 'unknown')
47
+ if result_type == 'ad':
48
+ st.success(f"### Result: ADVERTISEMENT")
49
+ else:
50
+ st.info(f"### Result: NON-ADVERTISEMENT")
51
+
52
+ # 2. Diagnostics Data
53
+ st.subheader("Full Diagnostics")
54
+ st.markdown("Below are the classification details, probabilities, and rule scores:")
55
+
56
+ # Display as pretty JSON
57
+ st.json(main_result)
58
+
59
+ except Exception as e:
60
+ st.error(f"Error during processing: {e}")
61
+ else:
62
+ st.warning("Please enter some text first.")
requirements.txt ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ streamlit
2
+ git+https://github.com/impresso/impresso-pipelines.git@ad_model_pipeline#egg=impresso_pipelines[adclassifier]