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

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +21 -5
app.py CHANGED
@@ -1,11 +1,11 @@
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
  """
@@ -26,11 +26,27 @@ def main():
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'])
 
1
  import streamlit as st
2
  from transformers import pipeline
3
 
4
+ # Initialize pipelines for each NLP task
5
  ner = pipeline("ner")
6
  qa = pipeline("question-answering")
7
  text_gen = pipeline("text-generation")
8
+ summarization = pipeline("summarization")
9
 
10
  def main():
11
  """
 
26
  if user_input and selected_task:
27
  if selected_task == "NER":
28
  analysis = ner(user_input)
29
+ st.write("**Named Entities:**")
30
+ for entity in analysis:
31
+ st.write(f"- {entity['word']} ({entity['entity_group']})")
32
  elif selected_task == "QA":
33
+ # Provide context (optional) for QA
34
+ context = st.text_input("Enter Context (Optional):", "")
35
+ if context:
36
+ analysis = qa(question="Your question", context=context, padding="max_length")
37
+ else:
38
+ analysis = qa(question="Your question", context=user_input, padding="max_length")
39
+ st.write("**Answer:**", analysis['answer'])
40
  elif selected_task == "Text Generation":
41
+ # Choose generation task from another dropdown
42
+ generation_task = st.selectbox("Choose Generation Task:", ["Text summarization (short)", "Poem", "Code"])
43
+ if generation_task == "Text summarization (short)":
44
+ analysis = summarization(user_input, max_length=50, truncation=True)
45
+ else:
46
+ # Experiment with different prompts and max_length for creative text generation
47
+ prompt = st.text_input("Enter Prompt (Optional):", "")
48
+ analysis = text_gen(prompt if prompt else user_input, max_length=50, truncation=True)
49
+ st.write("**Generated Text:**", analysis[0]['generated_text'])
50
  else:
51
  analysis = summarization(user_input, max_length=100, truncation=True)
52
  st.write("**Summary:**", analysis[0]['summary_text'])