File size: 1,907 Bytes
77d34d6
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
adf70a1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
import streamlit as st
import requests
from utils import (
    fetch_from_web,
    analyze_sentiment,
    generate_comparative_sentiment,
    generate_final_report,
    get_summaries_by_sentiment,
    translate,
    text_to_speech,
)

st.title("Company Sentiment Analyzer")

company_name = st.text_input("Enter Company Name", "Tesla")
model_provider = st.selectbox("Model Provider", options=["Ollama", "Groq"])

if st.button("Fetch Sentiment Data"):
    web_results = fetch_from_web(company_name)

    if "sources" not in web_results:
        return {"error": "No sources found."}

    sentiment_output = [
        analyze_sentiment(article, model_provider)
        for article in web_results["sources"][:5]
    ]

    comparative_sentiment = generate_comparative_sentiment(sentiment_output)

    positive_summary, negative_summary, neutral_summary = get_summaries_by_sentiment(
        sentiment_output
    )

    final_report = generate_final_report(
        positive_summary,
        negative_summary,
        neutral_summary,
        comparative_sentiment,
        model_provider,
    )

    hindi_translation = translate(final_report, model_provider)
    audio_path = text_to_speech(hindi_translation)

    output_dict = {
        "company_name": company_name,
        "articles": sentiment_output,
        "comparative_sentiment": comparative_sentiment,
        "final_report": final_report,
        "hindi_translation": hindi_translation,
        "audio_url": audio_path,
    }

        st.subheader("Company Name")
        st.write(output_dict.get("company_name"))

        st.subheader("Final Report")
        st.write(output_dict.get("final_report"))

        st.subheader("πŸ”Š Audio Output")
        audio_file = "output.mp3"
        if audio_file:
            st.audio(audio_file)

    except requests.exceptions.RequestException as e:
        st.error(f"Error fetching data: {e}")


        
#