Spaces:
Runtime error
Runtime error
Create app.py
Browse files1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253import gradio as grfrom transformers import pipelinefrom wordcloud import WordCloudimport matplotlib.pyplot as pltimport io
# Load Hugging Face pipelinessentiment_model = pipeline("sentiment-analysis")summarizer = pipeline("summarization")
# Function to generate word clouddef generate_wordcloud(text): wordcloud = WordCloud(width=800, height=400, background_color="white").generate(text) img = io.BytesIO() plt.figure(figsize=(8, 4)) plt.imshow(wordcloud, interpolation="bilinear") plt.axis("off") plt.savefig(img, format="png") plt.close() return img.getvalue()
# Core functiondef analyze_text(user_input): # Sentiment sentiment = sentiment_model(user_input)[0]
# Summary try: summary = summarizer(user_input, max_length=60, min_length=10, do_sample=False)[0]['summary_text'] except Exception: summary = "Summary not available for very short text."
# Wordcloud wc_img = generate_wordcloud(user_input)
return f"**Label:** {sentiment['label']} | **Score:** {sentiment['score']:.2f}", summary, wc_img
# Gradio Interfacedemo = gr.Interface( fn=analyze_text, inputs=gr.Textbox(lines=5, placeholder="Enter stakeholder comment here..."), outputs=[ gr.Textbox(label="Sentiment"), gr.Textbox(label="Summary"), gr.Image(label="Word Cloud") ], title="E-Consultation Sentiment Analysis", description="Enter a comment/suggestion. The system predicts sentiment, generates a summary, and visualizes keywords.")
if __name__ == "__main__": demo.launch()app.pyAdded+53