Raghuan commited on
Commit
80a6910
·
verified ·
1 Parent(s): 27e5483

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +8 -21
app.py CHANGED
@@ -1,6 +1,11 @@
1
  import streamlit as st
2
  from transformers import pipeline
3
 
 
 
 
 
 
4
 
5
  def main():
6
  """
@@ -17,33 +22,15 @@ def main():
17
  # Select task from dropdown menu
18
  selected_task = st.selectbox("Choose NLP Task:", ["NER", "QA", "Text Generation", "Text Summarization"])
19
 
20
- # Initialize pipelines (including summarization) before conditional statements
21
- ner = pipeline("ner")
22
- qa = pipeline("question-answering")
23
- text_gen = pipeline("text-generation")
24
- summarization = pipeline("summarization")
25
-
26
  # Perform NLP task based on selection
27
  if user_input and selected_task:
28
  if selected_task == "NER":
29
  analysis = ner(user_input)
30
- st.write("**Named Entities:**")
31
- for entity in analysis:
32
- # Check for 'label' or 'group' key in entity
33
- entity_group = entity.get('label', entity.get('group', 'NA'))
34
- st.write(f"- {entity['word']} ({entity_group})")
35
  elif selected_task == "QA":
36
  # ... rest of QA code
37
- elif selected_task == "Text Generation": # Ensure proper indentation here
38
- # Choose generation task from another dropdown
39
- generation_task = st.selectbox("Choose Generation Task:", ["Text summarization (short)", "Poem", "Code"])
40
- if generation_task == "Text summarization (short)":
41
- analysis = summarization(user_input, max_length=50, truncation=True)
42
- else:
43
- # Experiment with different prompts and max_length for creative text generation
44
- prompt = st.text_input("Enter Prompt (Optional):", "")
45
- analysis = text_gen(prompt if prompt else user_input, max_length=50, truncation=True)
46
- st.write("**Generated Text:**", analysis[0]['generated_text'])
47
  else:
48
  analysis = summarization(user_input, max_length=100, truncation=True)
49
  st.write("**Summary:**", analysis[0]['summary_text'])
 
1
  import streamlit as st
2
  from transformers import pipeline
3
 
4
+ # Initialize pipelines (including summarization)
5
+ ner = pipeline("ner")
6
+ qa = pipeline("question-answering")
7
+ text_gen = pipeline("text-generation")
8
+ summarization = pipeline("summarization") # Initialize summarization pipeline here
9
 
10
  def main():
11
  """
 
22
  # Select task from dropdown menu
23
  selected_task = st.selectbox("Choose NLP Task:", ["NER", "QA", "Text Generation", "Text Summarization"])
24
 
 
 
 
 
 
 
25
  # Perform NLP task based on selection
26
  if user_input and selected_task:
27
  if selected_task == "NER":
28
  analysis = ner(user_input)
29
+ # ... rest of NER code
 
 
 
 
30
  elif selected_task == "QA":
31
  # ... rest of QA code
32
+ elif selected_task == "Text Generation":
33
+ # ... rest of Text Generation code
 
 
 
 
 
 
 
 
34
  else:
35
  analysis = summarization(user_input, max_length=100, truncation=True)
36
  st.write("**Summary:**", analysis[0]['summary_text'])