Spaces:
Build error
Build error
Upload app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
from transformers import pipeline
|
| 3 |
+
|
| 4 |
+
|
| 5 |
+
def summarize_text(input_text):
|
| 6 |
+
summarize=pipeline("summarization", model="Falconsai/text_summarization")
|
| 7 |
+
summary= summarize(input_text,max_length=1000,min_length=128,do_sample=False)
|
| 8 |
+
return summary[0]['summary_text']
|
| 9 |
+
#summary_text=summarize_text(text)
|
| 10 |
+
def translate_urdu(english_summary):
|
| 11 |
+
translator = pipeline("translation", model="Helsinki-NLP/opus-mt-en-ur")
|
| 12 |
+
urdu_text=translator(english_summary)
|
| 13 |
+
urdu_summary=urdu_text[0]['translation_text']
|
| 14 |
+
return urdu_text[0]['translation_text']
|
| 15 |
+
|
| 16 |
+
def main():
|
| 17 |
+
|
| 18 |
+
st.title(" Text Summarization and Translation")
|
| 19 |
+
input_text= st.text_area("Enter text to summarize:","")
|
| 20 |
+
if st.button("Summarize"):
|
| 21 |
+
if input_text:
|
| 22 |
+
st.write("English Summary:")
|
| 23 |
+
english_summary=summarize_text(input_text)
|
| 24 |
+
st.write(english_summary)
|
| 25 |
+
if st.button("Translate English to Urdu"):
|
| 26 |
+
urdu_translation=translate_urdu(english_summary)
|
| 27 |
+
st.write("Urdu Translation")
|
| 28 |
+
st.write(urdu_translation)
|
| 29 |
+
st.write("English summary text")
|
| 30 |
+
st.write(english_summary)
|
| 31 |
+
if __name__=="__main__":
|
| 32 |
+
main()
|