Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -410,7 +410,6 @@
|
|
410 |
# #examples=[['manifestos/Bjp_Manifesto_2019.pdf','modi'],['AAP_Manifesto_2019.pdf','delhi'],['manifestos/Congress_Manifesto_2019.pdf','safety']])
|
411 |
|
412 |
|
413 |
-
|
414 |
"""
|
415 |
# MANIFESTO ANALYSIS
|
416 |
"""
|
@@ -843,50 +842,71 @@ url="https://drive.google.com/uc?id=1HVZvTtYntl0YKLnE0cwu0CvAIRhXOv60&export=dow
|
|
843 |
path_input = "./Congress_Manifesto_2019.pdf"
|
844 |
urllib.request.urlretrieve(url, filename=path_input)
|
845 |
'''
|
846 |
-
def analysis(Manifesto,Search):
|
847 |
-
|
848 |
-
|
849 |
-
|
850 |
-
|
851 |
-
|
852 |
-
|
853 |
-
|
854 |
-
|
855 |
-
|
856 |
-
|
857 |
-
|
858 |
-
|
859 |
-
|
860 |
-
|
861 |
-
|
862 |
-
|
863 |
-
|
864 |
-
|
865 |
-
|
866 |
-
|
867 |
-
buf.seek(0)
|
868 |
-
img1 = Image.open(buf)
|
869 |
-
plt.clf()
|
870 |
-
|
871 |
-
plt.figure(figsize=(4,3))
|
872 |
-
df['Analysis on Subjectivity'].value_counts().plot(kind ='bar',color="#B667F1")
|
873 |
-
plt.tight_layout()
|
874 |
-
buf = BytesIO()
|
875 |
-
plt.savefig(buf)
|
876 |
-
buf.seek(0)
|
877 |
-
img2 = Image.open(buf)
|
878 |
-
plt.clf()
|
879 |
|
880 |
-
|
881 |
-
|
882 |
-
|
883 |
-
|
884 |
-
|
885 |
-
|
886 |
-
|
887 |
-
|
888 |
-
|
889 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
890 |
|
891 |
|
892 |
Search_txt= "text"
|
@@ -954,6 +974,8 @@ with gr.Blocks(title='Manifesto Analysis') as demo:
|
|
954 |
demo.launch(debug=True, share=False)
|
955 |
|
956 |
|
957 |
-
#
|
958 |
-
#examples=[['
|
|
|
|
|
959 |
|
|
|
410 |
# #examples=[['manifestos/Bjp_Manifesto_2019.pdf','modi'],['AAP_Manifesto_2019.pdf','delhi'],['manifestos/Congress_Manifesto_2019.pdf','safety']])
|
411 |
|
412 |
|
|
|
413 |
"""
|
414 |
# MANIFESTO ANALYSIS
|
415 |
"""
|
|
|
842 |
path_input = "./Congress_Manifesto_2019.pdf"
|
843 |
urllib.request.urlretrieve(url, filename=path_input)
|
844 |
'''
|
845 |
+
def analysis(Manifesto, Search):
|
846 |
+
'''
|
847 |
+
Main analysis function that processes the manifesto and generates all outputs
|
848 |
+
Manifesto: PDF file uploaded by the user
|
849 |
+
Search: Search term entered by the user
|
850 |
+
'''
|
851 |
+
try:
|
852 |
+
# Process the uploaded PDF
|
853 |
+
raw_party = Parsing(Manifesto)
|
854 |
+
text_Party = clean_text(raw_party)
|
855 |
+
text_Party_processed = Preprocess(text_Party)
|
856 |
+
|
857 |
+
# Generate summary using LLM
|
858 |
+
summary = generate_summary(raw_party)
|
859 |
+
|
860 |
+
# Sentiment analysis
|
861 |
+
df = pd.DataFrame(raw_party.split('\n'), columns=['Content'])
|
862 |
+
df['Subjectivity'] = df['Content'].apply(getSubjectivity)
|
863 |
+
df['Polarity'] = df['Content'].apply(getPolarity)
|
864 |
+
df['Analysis on Polarity'] = df['Polarity'].apply(getAnalysis)
|
865 |
+
df['Analysis on Subjectivity'] = df['Subjectivity'].apply(getAnalysis)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
866 |
|
867 |
+
# Generate sentiment analysis plot
|
868 |
+
plt.title('Sentiment Analysis')
|
869 |
+
plt.xlabel('Sentiment')
|
870 |
+
plt.ylabel('Counts')
|
871 |
+
plt.figure(figsize=(4,3))
|
872 |
+
df['Analysis on Polarity'].value_counts().plot(kind ='bar',color="#FF9F45")
|
873 |
+
plt.tight_layout()
|
874 |
+
buf = BytesIO()
|
875 |
+
plt.savefig(buf)
|
876 |
+
buf.seek(0)
|
877 |
+
img1 = Image.open(buf)
|
878 |
+
plt.clf()
|
879 |
+
|
880 |
+
# Generate subjectivity analysis plot
|
881 |
+
plt.figure(figsize=(4,3))
|
882 |
+
df['Analysis on Subjectivity'].value_counts().plot(kind ='bar',color="#B667F1")
|
883 |
+
plt.tight_layout()
|
884 |
+
buf = BytesIO()
|
885 |
+
plt.savefig(buf)
|
886 |
+
buf.seek(0)
|
887 |
+
img2 = Image.open(buf)
|
888 |
+
plt.clf()
|
889 |
+
|
890 |
+
# Generate word cloud
|
891 |
+
img3 = word_cloud_generator(Manifesto.name, text_Party_processed)
|
892 |
+
|
893 |
+
# Generate frequency distribution and dispersion plots
|
894 |
+
fdist_Party = fDistance(text_Party_processed)
|
895 |
+
img4 = fDistancePlot(text_Party_processed)
|
896 |
+
img5 = DispersionPlot(text_Party_processed)
|
897 |
+
|
898 |
+
# Search for the term in the text
|
899 |
+
searChRes = get_all_phases_containing_tar_wrd(Search, text_Party_processed)
|
900 |
+
searChRes = searChRes.replace(Search, "\u0332".join(Search))
|
901 |
+
|
902 |
+
plt.close('all')
|
903 |
+
return searChRes, fdist_Party, img1, img2, img3, img4, img5, summary
|
904 |
+
|
905 |
+
except Exception as e:
|
906 |
+
error_message = f"Error analyzing manifesto: {str(e)}"
|
907 |
+
print(error_message)
|
908 |
+
# Return placeholder values in case of error
|
909 |
+
return error_message, {}, None, None, None, None, None, "Error generating summary. Please check the console for details."
|
910 |
|
911 |
|
912 |
Search_txt= "text"
|
|
|
974 |
demo.launch(debug=True, share=False)
|
975 |
|
976 |
|
977 |
+
# Old interface code replaced by the Blocks implementation above
|
978 |
+
# io=gr.Interface(fn=analysis, inputs=[filePdf,Search_txt], outputs=[text,mfw,plot1,plot2,plot3,plot4,plot5], title='Manifesto Analysis',examples=[['Example/AAP_Manifesto_2019.pdf','government'],['Example/Bjp_Manifesto_2019.pdf','environment'],['Example/Congress_Manifesto_2019.pdf','safety']])
|
979 |
+
# io.launch(debug=True,share=False)
|
980 |
+
|
981 |
|