KishanKumar001 commited on
Commit
ace7b0f
·
1 Parent(s): d78af2d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +69 -18
app.py CHANGED
@@ -1,20 +1,18 @@
 
 
 
1
  import tkinter as tk
2
  from tkinter import scrolledtext
3
  import requests
4
- import os
5
  SECRET_TOKEN = os.getenv("SECRET_TOKEN")
6
 
7
  API_URL = "https://api-inference.huggingface.co/models/ahmedrachid/FinancialBERT-Sentiment-Analysis"
8
- headers = {"Authorization": "Bearer {SECRET_TOKEN}"}
9
 
10
  def query(payload):
11
- response = requests.post(API_URL, headers=headers, json=payload)
12
- return response.json()
13
-
14
- # output = query({
15
- # "inputs": "I like you. I love you",
16
- # })
17
-
18
 
19
  def get_user_input():
20
  user_query = user_input.get("1.0", tk.END).strip()
@@ -22,29 +20,82 @@ def get_user_input():
22
  output = query({"inputs": user_query})
23
  output_text.insert(tk.END, output)
24
 
25
-
26
  window = tk.Tk()
27
- window.title("Query Interface")
28
-
29
 
30
- user_input_label = tk.Label(window, text="Enter your query:")
31
  user_input_label.pack()
32
 
33
  user_input = scrolledtext.ScrolledText(window, width=40, height=5, wrap=tk.WORD)
34
  user_input.pack()
35
 
36
-
37
- query_button = tk.Button(window, text="Query", command=get_user_input)
38
  query_button.pack()
39
 
40
-
41
- output_text_label = tk.Label(window, text="Output:")
42
  output_text_label.pack()
43
 
44
  output_text = scrolledtext.ScrolledText(window, width=40, height=10, wrap=tk.WORD)
45
  output_text.pack()
46
 
47
-
48
  window.mainloop()
49
 
50
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ import matplotlib
3
+ matplotlib.use('Agg') # Use the 'Agg' backend for non-interactive use
4
  import tkinter as tk
5
  from tkinter import scrolledtext
6
  import requests
7
+
8
  SECRET_TOKEN = os.getenv("SECRET_TOKEN")
9
 
10
  API_URL = "https://api-inference.huggingface.co/models/ahmedrachid/FinancialBERT-Sentiment-Analysis"
11
+ headers = {"Authorization": f"Bearer {SECRET_TOKEN}"}
12
 
13
  def query(payload):
14
+ response = requests.post(API_URL, headers=headers, json=payload)
15
+ return response.json()
 
 
 
 
 
16
 
17
  def get_user_input():
18
  user_query = user_input.get("1.0", tk.END).strip()
 
20
  output = query({"inputs": user_query})
21
  output_text.insert(tk.END, output)
22
 
 
23
  window = tk.Tk()
24
+ window.title("Hugging Face Sentiment Analysis")
 
25
 
26
+ user_input_label = tk.Label(window, text="Enter your text:")
27
  user_input_label.pack()
28
 
29
  user_input = scrolledtext.ScrolledText(window, width=40, height=5, wrap=tk.WORD)
30
  user_input.pack()
31
 
32
+ query_button = tk.Button(window, text="Analyze Sentiment", command=get_user_input)
 
33
  query_button.pack()
34
 
35
+ output_text_label = tk.Label(window, text="Sentiment Analysis Output:")
 
36
  output_text_label.pack()
37
 
38
  output_text = scrolledtext.ScrolledText(window, width=40, height=10, wrap=tk.WORD)
39
  output_text.pack()
40
 
 
41
  window.mainloop()
42
 
43
 
44
+
45
+
46
+
47
+
48
+
49
+
50
+
51
+
52
+ # import tkinter as tk
53
+ # from tkinter import scrolledtext
54
+ # import requests
55
+ # import os
56
+ # SECRET_TOKEN = os.getenv("SECRET_TOKEN")
57
+
58
+ # API_URL = "https://api-inference.huggingface.co/models/ahmedrachid/FinancialBERT-Sentiment-Analysis"
59
+ # headers = {"Authorization": "Bearer {SECRET_TOKEN}"}
60
+
61
+ # def query(payload):
62
+ # response = requests.post(API_URL, headers=headers, json=payload)
63
+ # return response.json()
64
+
65
+ # # output = query({
66
+ # # "inputs": "I like you. I love you",
67
+ # # })
68
+
69
+
70
+ # def get_user_input():
71
+ # user_query = user_input.get("1.0", tk.END).strip()
72
+ # output_text.delete(1.0, tk.END) # Clear previous output
73
+ # output = query({"inputs": user_query})
74
+ # output_text.insert(tk.END, output)
75
+
76
+
77
+ # window = tk.Tk()
78
+ # window.title("Query Interface")
79
+
80
+
81
+ # user_input_label = tk.Label(window, text="Enter your query:")
82
+ # user_input_label.pack()
83
+
84
+ # user_input = scrolledtext.ScrolledText(window, width=40, height=5, wrap=tk.WORD)
85
+ # user_input.pack()
86
+
87
+
88
+ # query_button = tk.Button(window, text="Query", command=get_user_input)
89
+ # query_button.pack()
90
+
91
+
92
+ # output_text_label = tk.Label(window, text="Output:")
93
+ # output_text_label.pack()
94
+
95
+ # output_text = scrolledtext.ScrolledText(window, width=40, height=10, wrap=tk.WORD)
96
+ # output_text.pack()
97
+
98
+
99
+ # window.mainloop()
100
+
101
+