uumerrr684 commited on
Commit
3d098ca
·
verified ·
1 Parent(s): 0891f1f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +13 -99
app.py CHANGED
@@ -2,126 +2,40 @@ import os
2
  import requests
3
  import gradio as gr
4
 
5
- # Token setup
6
  TOKEN = os.getenv("HF_API_TOKEN", "").strip()
7
 
8
  def summarize(text):
 
9
  try:
10
- if not TOKEN.startswith("hf_"):
11
- return "🔴 Invalid token format", ""
12
-
13
  response = requests.post(
14
  "https://api-inference.huggingface.co/models/facebook/bart-large-cnn",
15
  headers={"Authorization": f"Bearer {TOKEN}"},
16
  json={"inputs": text[:2000], "parameters": {"max_length": 100}},
17
  timeout=20
18
  )
19
-
20
- if response.ok:
21
- return response.json()[0]['summary_text'], "✅ Success"
22
- return f"⚠️ API Error {response.status_code}", ""
23
-
24
  except Exception as e:
25
- return f"🚨 Error: {str(e)}", ""
26
 
27
- # ======= PURPLE THEME ======= #
28
- custom_css = """
29
- .gradio-container {
30
  background: #6A0DAD !important;
31
  color: white !important;
32
- max-width: 800px;
33
- margin: auto;
34
- border-radius: 15px;
35
- padding: 20px;
36
- }
37
- #input-box, #output-box {
38
- font-family: 'Arial', sans-serif;
39
- border-radius: 10px !important;
40
- padding: 15px !important;
41
- background: #8A2BE2 !important;
42
- color: white !important;
43
- border: 2px solid #9370DB !important;
44
- }
45
- #input-box::placeholder {
46
- color: #D8BFD8 !important;
47
- }
48
- #submit-btn, .clear-btn {
49
- background: #9370DB !important;
50
- color: white !important;
51
  border: none !important;
52
  border-radius: 8px !important;
53
- padding: 12px 24px !important;
54
- font-weight: bold !important;
55
- margin: 5px !important;
56
- }
57
- #submit-btn:hover, .clear-btn:hover {
58
- background: #8A2BE2 !important;
59
- transform: scale(1.02);
60
- }
61
- .header {
62
- text-align: center;
63
- font-size: 2em !important;
64
- color: white !important;
65
- margin-bottom: 10px !important;
66
  }
67
- .subheader {
68
- text-align: center;
69
- color: #D8BFD8 !important;
70
- margin-bottom: 20px !important;
71
- }
72
- .status {
73
  background: #8A2BE2 !important;
74
- color: white !important;
75
- border-radius: 8px;
76
- padding: 10px;
77
- text-align: center;
78
- }
79
- label {
80
- color: white !important;
81
- font-weight: bold !important;
82
- }
83
- footer {
84
- visibility: hidden;
85
  }
86
  """
87
 
88
- with gr.Blocks(css=custom_css) as app:
89
- gr.Markdown("""
90
- <div class='header'>✨ SUMMIFY PRO ✨</div>
91
- <div class='subheader'>Transform texts into concise summaries</div>
92
- """)
93
-
94
  with gr.Row():
95
- input_txt = gr.Textbox(
96
- label="Your Text",
97
- placeholder="Type or paste your content here...",
98
- lines=7,
99
- elem_id="input-box"
100
- )
101
- output_txt = gr.Textbox(
102
- label="Summary",
103
- lines=7,
104
- elem_id="output-box",
105
- interactive=False
106
- )
107
-
108
- status = gr.Textbox(
109
- label="Status",
110
- interactive=False,
111
- elem_classes="status"
112
- )
113
-
114
- with gr.Row():
115
- gr.Button(
116
- "Summarize",
117
- elem_id="submit-btn"
118
- )
119
- gr.Button(
120
- "Clear",
121
- elem_classes="clear-btn"
122
- ).click(
123
- lambda: ["", "", ""],
124
- outputs=[input_txt, output_txt, status]
125
- )
126
 
127
  app.launch(server_name="0.0.0.0")
 
2
  import requests
3
  import gradio as gr
4
 
 
5
  TOKEN = os.getenv("HF_API_TOKEN", "").strip()
6
 
7
  def summarize(text):
8
+ if not text.strip(): return "Please enter text", ""
9
  try:
 
 
 
10
  response = requests.post(
11
  "https://api-inference.huggingface.co/models/facebook/bart-large-cnn",
12
  headers={"Authorization": f"Bearer {TOKEN}"},
13
  json={"inputs": text[:2000], "parameters": {"max_length": 100}},
14
  timeout=20
15
  )
16
+ return (response.json()[0]['summary_text'], "✅ Success") if response.ok else (f"⚠️ Error {response.status_code}", "")
 
 
 
 
17
  except Exception as e:
18
+ return f"🚨 {str(e)}", ""
19
 
20
+ css = """
21
+ button {
 
22
  background: #6A0DAD !important;
23
  color: white !important;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
24
  border: none !important;
25
  border-radius: 8px !important;
 
 
 
 
 
 
 
 
 
 
 
 
 
26
  }
27
+ button:hover {
 
 
 
 
 
28
  background: #8A2BE2 !important;
 
 
 
 
 
 
 
 
 
 
 
29
  }
30
  """
31
 
32
+ with gr.Blocks(css=css) as app:
33
+ gr.Markdown("## ✨ SUMMIFY PRO")
 
 
 
 
34
  with gr.Row():
35
+ input_txt = gr.Textbox(label="Your Text", placeholder="Type here...", lines=5)
36
+ output_txt = gr.Textbox(label="Summary", interactive=False, lines=5)
37
+ status = gr.Textbox(label="Status", interactive=False)
38
+ gr.Button("Summarize").click(summarize, input_txt, [output_txt, status])
39
+ gr.Button("Clear").click(lambda: ["", "", ""], [input_txt, output_txt, status])
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
40
 
41
  app.launch(server_name="0.0.0.0")