| import os | |
| import matplotlib | |
| matplotlib.use('Agg') # Use the 'Agg' backend for non-interactive use | |
| 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() | |
| def get_user_input(): | |
| user_query = user_input.get("1.0", tk.END).strip() | |
| output_text.delete(1.0, tk.END) # Clear previous output | |
| output = query({"inputs": user_query}) | |
| output_text.insert(tk.END, output) | |
| window = tk.Tk() | |
| window.title("Hugging Face Sentiment Analysis") | |
| user_input_label = tk.Label(window, text="Enter your text:") | |
| user_input_label.pack() | |
| user_input = scrolledtext.ScrolledText(window, width=40, height=5, wrap=tk.WORD) | |
| user_input.pack() | |
| query_button = tk.Button(window, text="Analyze Sentiment", command=get_user_input) | |
| query_button.pack() | |
| output_text_label = tk.Label(window, text="Sentiment Analysis Output:") | |
| output_text_label.pack() | |
| output_text = scrolledtext.ScrolledText(window, width=40, height=10, wrap=tk.WORD) | |
| output_text.pack() | |
| window.mainloop() | |
| # import tkinter as tk | |
| # from tkinter import scrolledtext | |
| # import requests | |
| # import os | |
| # SECRET_TOKEN = os.getenv("SECRET_TOKEN") | |
| # API_URL = "https://api-inference.huggingface.co/models/ahmedrachid/FinancialBERT-Sentiment-Analysis" | |
| # headers = {"Authorization": "Bearer {SECRET_TOKEN}"} | |
| # def query(payload): | |
| # response = requests.post(API_URL, headers=headers, json=payload) | |
| # return response.json() | |
| # # output = query({ | |
| # # "inputs": "I like you. I love you", | |
| # # }) | |
| # def get_user_input(): | |
| # user_query = user_input.get("1.0", tk.END).strip() | |
| # output_text.delete(1.0, tk.END) # Clear previous output | |
| # output = query({"inputs": user_query}) | |
| # output_text.insert(tk.END, output) | |
| # window = tk.Tk() | |
| # window.title("Query Interface") | |
| # user_input_label = tk.Label(window, text="Enter your query:") | |
| # user_input_label.pack() | |
| # user_input = scrolledtext.ScrolledText(window, width=40, height=5, wrap=tk.WORD) | |
| # user_input.pack() | |
| # query_button = tk.Button(window, text="Query", command=get_user_input) | |
| # query_button.pack() | |
| # output_text_label = tk.Label(window, text="Output:") | |
| # output_text_label.pack() | |
| # output_text = scrolledtext.ScrolledText(window, width=40, height=10, wrap=tk.WORD) | |
| # output_text.pack() | |
| # window.mainloop() | |