Tamara Adokeme commited on
Commit
7f8f9cc
·
1 Parent(s): 37cd9ed

Update app.py

Browse files
Files changed (3) hide show
  1. .gitignore +2 -0
  2. app.py +14 -22
  3. requirements.txt +1 -59
.gitignore ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ Untitled.ipynb
2
+ .ipynb_checkpoints/Untitled-checkpoint.ipynb
app.py CHANGED
@@ -1,28 +1,20 @@
1
- from transformers import GPT2LMHeadModel, GPT2TokenizerFast
2
  import streamlit as st
3
 
4
- # Load pre-trained GPT-2 model and tokenizer
5
- model_name = "gpt2" # You can try other GPT-2 variants as well
6
- tokenizer = GPT2TokenizerFast.from_pretrained(model_name)
7
- model = GPT2LMHeadModel.from_pretrained(model_name, pad_token_id=tokenizer.eos_token_id)
8
 
9
- st.title("Theme Generation App")
 
10
 
11
- # Create a textarea for user input
12
- user_text = st.text_area("Enter Text:", "Type here...")
13
 
14
- if st.button("Generate Themes"):
15
- # Construct a prompt for thematic generation
16
- prompt = f"Reply with at most seven possible themes detected in the text: {user_text}\nThemes:"
 
 
17
 
18
- # Tokenize the prompt
19
- input_ids = tokenizer.encode(prompt, return_tensors="pt")
20
-
21
- # Generate themes using GPT-2
22
- output = model.generate(input_ids, max_new_tokens=10, num_beams=5, no_repeat_ngram_size=2, top_k=50, top_p=0.95, temperature=0.5)
23
-
24
- # Decode the generated themes
25
- generated_themes = tokenizer.decode(output[0], skip_special_tokens=True)
26
-
27
- # Display the generated themes
28
- st.success(f"Generated Themes: {generated_themes}")
 
1
+ from transformers import pipeline
2
  import streamlit as st
3
 
4
+ model_name = "FPRT/bert-fine-tuned-stepkids-classification"
5
+ pipe = pipeline(model=model_name)
 
 
6
 
7
+ def main():
8
+ st.title("Hugging Face Model Demo")
9
 
10
+ # Create an input text box
11
+ input_text = st.text_input("Enter your text", "")
12
 
13
+ # Create a button to trigger model inference
14
+ if st.button("Analyze"):
15
+ # Perform inference using the loaded model
16
+ result = pipe(input_text)
17
+ st.write("Prediction:", result[0]['label'], "| Score:", result[0]['score'])
18
 
19
+ if __name__ == "__main__":
20
+ main()
 
 
 
 
 
 
 
 
 
requirements.txt CHANGED
@@ -1,59 +1 @@
1
- altair==5.1.2
2
- attrs==23.1.0
3
- blinker==1.7.0
4
- cachetools==5.3.2
5
- certifi==2023.7.22
6
- charset-normalizer==3.3.2
7
- click==8.1.7
8
- colorama==0.4.6
9
- filelock==3.13.1
10
- fsspec==2023.10.0
11
- gitdb==4.0.11
12
- GitPython==3.1.40
13
- huggingface-hub==0.17.3
14
- idna==3.4
15
- importlib-metadata==6.8.0
16
- Jinja2==3.1.2
17
- jsonschema==4.19.2
18
- jsonschema-specifications==2023.7.1
19
- markdown-it-py==3.0.0
20
- MarkupSafe==2.1.3
21
- mdurl==0.1.2
22
- mpmath==1.3.0
23
- networkx==3.2.1
24
- numpy==1.26.1
25
- packaging==23.2
26
- pandas==2.1.2
27
- Pillow==10.1.0
28
- protobuf==4.25.0
29
- pyarrow==14.0.0
30
- pydeck==0.8.1b0
31
- Pygments==2.16.1
32
- python-dateutil==2.8.2
33
- pytz==2023.3.post1
34
- PyYAML==6.0.1
35
- referencing==0.30.2
36
- regex==2023.10.3
37
- requests==2.31.0
38
- rich==13.6.0
39
- rpds-py==0.12.0
40
- safetensors==0.4.0
41
- six==1.16.0
42
- smmap==5.0.1
43
- streamlit==1.28.1
44
- sympy==1.12
45
- tenacity==8.2.3
46
- tokenizers==0.14.1
47
- toml==0.10.2
48
- toolz==0.12.0
49
- torch==2.1.0
50
- tornado==6.3.3
51
- tqdm==4.66.1
52
- transformers==4.35.0
53
- typing_extensions==4.8.0
54
- tzdata==2023.3
55
- tzlocal==5.2
56
- urllib3==2.0.7
57
- validators==0.22.0
58
- watchdog==3.0.0
59
- zipp==3.17.0
 
1
+ streamlit-tags