jonathanagustin commited on
Commit
6c86a1d
·
verified ·
1 Parent(s): c468fb4

Sync from deploy tool: tutorials/01-sentiment-explorer

Browse files
Files changed (3) hide show
  1. .env.example +5 -0
  2. README.md +2 -1
  3. app.py +9 -1
.env.example ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
 
1
+ # Hugging Face token (required for Inference API)
2
+ HF_TOKEN=
3
+
4
+ # Sentiment model (defaults to DistilBERT SST-2)
5
+ MODEL_ID=distilbert/distilbert-base-uncased-finetuned-sst-2-english
README.md CHANGED
@@ -12,7 +12,8 @@ license: mit
12
 
13
  # 🎭 Sentiment Explorer
14
 
15
- Analyze the emotional tone of any text using DistilBERT via the HuggingFace Inference API.
 
16
 
17
  ## Features
18
 
 
12
 
13
  # 🎭 Sentiment Explorer
14
 
15
+ Analyze the emotional tone of any text using DistilBERT via the HuggingFace
16
+ Inference API.
17
 
18
  ## Features
19
 
app.py CHANGED
@@ -21,6 +21,14 @@ logger.info(f"MODEL_ID: {MODEL_ID}")
21
  client = InferenceClient(token=HF_TOKEN) if HF_TOKEN else InferenceClient()
22
  logger.info("InferenceClient initialized")
23
 
 
 
 
 
 
 
 
 
24
 
25
 
26
  def analyze(text: str) -> tuple[str, dict]:
@@ -48,7 +56,7 @@ def analyze(text: str) -> tuple[str, dict]:
48
 
49
  logger.info("Building Gradio interface...")
50
 
51
- with gr.Blocks(title="Sentiment Explorer") as demo:
52
  gr.Markdown("# 🎭 Sentiment Explorer\nType anything and see if it's positive or negative!")
53
 
54
  inp = gr.Textbox(
 
21
  client = InferenceClient(token=HF_TOKEN) if HF_TOKEN else InferenceClient()
22
  logger.info("InferenceClient initialized")
23
 
24
+ # Force dark mode via URL parameter
25
+ FORCE_DARK_MODE = """
26
+ function() {
27
+ if (document.querySelectorAll('.dark').length === 0) {
28
+ document.querySelector('body').classList.add('dark');
29
+ }
30
+ }
31
+ """
32
 
33
 
34
  def analyze(text: str) -> tuple[str, dict]:
 
56
 
57
  logger.info("Building Gradio interface...")
58
 
59
+ with gr.Blocks(title="Sentiment Explorer", js=FORCE_DARK_MODE) as demo:
60
  gr.Markdown("# 🎭 Sentiment Explorer\nType anything and see if it's positive or negative!")
61
 
62
  inp = gr.Textbox(