File size: 1,476 Bytes
7c09551
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
ace7b0f
010a8fb
887db57
ace7b0f
384368c
887db57
 
ace7b0f
887db57
 
ace7b0f
 
c4251ad
010a8fb
 
7c09551
 
 
 
 
 
010a8fb
5f8a61a
ace7b0f
 
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
# import os
# import matplotlib
# matplotlib.use('Agg')  # Use the 'Agg' backend for non-interactive use
# import streamlit as st
# import tkinter as tk
# from tkinter import scrolledtext
# import requests

# SECRET_TOKEN = os.getenv("SECRET_TOKEN")

# API_URL = "https://api-inference.huggingface.co/models/ahmedrachid/FinancialBERT-Sentiment-Analysis"
# headers = {"Authorization": f"Bearer {SECRET_TOKEN}"}

# def query(payload):
#     response = requests.post(API_URL, headers=headers, json=payload)
#     return response.json()

# user_query = st.text_area("Enter your text:")
# if st.button("Analyze Sentiment"):
#     output = query({"inputs": user_query})
#     st.text("Sentiment Analysis Output:")
#     st.text(output[0][0]['label'])


import os
import streamlit as st
import requests

SECRET_TOKEN = os.getenv("SECRET_TOKEN")

API_URL = "https://api-inference.huggingface.co/models/ahmedrachid/FinancialBERT-Sentiment-Analysis"
headers = {"Authorization": f"Bearer {SECRET_TOKEN}"}

def query(payload):
    response = requests.post(API_URL, headers=headers, json=payload)
    return response.json()

user_query = st.text_area("Enter your text:")
if st.button("Analyze Sentiment"):
    # Show loading message while the model is loading
    with st.spinner("Analyzing..."):
        # Load the model
        output = query({"inputs": user_query})
    
    # Display results after loading
    st.text("Sentiment Analysis Output:")
    st.text(output[0][0]['label'])