Quanttum commited on
Commit
99281ee
Β·
verified Β·
1 Parent(s): 8cc9472

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +28 -11
app.py CHANGED
@@ -4,23 +4,29 @@ from peft import PeftModel
4
  import torch
5
  import re
6
 
7
- # THIS LINE IS THE ONLY CHANGE β€” un-gated, public, works instantly
8
- model_name = "unsloth/Meta-Llama-3.1-8B-Instruct-bnb-4bit"
 
9
 
10
- tokenizer = AutoTokenizer.from_pretrained(model_name)
 
11
  base_model = AutoModelForCausalLM.from_pretrained(
12
- model_name,
13
  torch_dtype=torch.float16,
14
  device_map="auto"
15
  )
16
- model = PeftModel.from_pretrained(base_model, "Quanttum/crypto-llama-lora-final")
17
 
 
 
 
 
18
  pipe = pipeline(
19
  "text-generation",
20
  model=model,
21
  tokenizer=tokenizer,
22
  max_new_tokens=512,
23
  temperature=0.3,
 
24
  repetition_penalty=1.15,
25
  )
26
 
@@ -35,17 +41,28 @@ TL;DR:"""
35
 
36
  output = pipe(prompt)[0]["generated_text"]
37
  response = output[len(prompt):].strip()
38
- return response
39
 
40
- with gr.Blocks(theme=gr.themes.Soft()) as demo:
41
- gr.Markdown("# πŸš€ Crypto News Summarizer + Sentiment Analyzer\nFine-tuned Llama 3.1 8B")
42
- gr.ChatInterface(
 
 
 
 
 
 
 
 
 
43
  chat,
44
  examples=[
45
- ["Bitcoin ETF inflows hit $1.5B this week!"],
 
46
  ["SEC approves spot Ethereum ETF!"],
47
- ["Mt. Gox starts repaying creditors in BTC."],
48
  ],
 
 
49
  cache_examples=True,
50
  )
51
 
 
4
  import torch
5
  import re
6
 
7
+ # Public, ungated base model + your LoRA (works 100% in Spaces)
8
+ base_name = "unsloth/Meta-Llama-3.1-8B-Instruct-bnb-4bit"
9
+ lora_name = "Quanttum/crypto-llama-lora-final"
10
 
11
+ # Load base model (no auth needed)
12
+ tokenizer = AutoTokenizer.from_pretrained(base_name)
13
  base_model = AutoModelForCausalLM.from_pretrained(
14
+ base_name,
15
  torch_dtype=torch.float16,
16
  device_map="auto"
17
  )
 
18
 
19
+ # Load your LoRA on top (your fine-tuning!)
20
+ model = PeftModel.from_pretrained(base_model, lora_name)
21
+
22
+ # Pipeline for generation
23
  pipe = pipeline(
24
  "text-generation",
25
  model=model,
26
  tokenizer=tokenizer,
27
  max_new_tokens=512,
28
  temperature=0.3,
29
+ top_p=0.9,
30
  repetition_penalty=1.15,
31
  )
32
 
 
41
 
42
  output = pipe(prompt)[0]["generated_text"]
43
  response = output[len(prompt):].strip()
 
44
 
45
+ # Simple score extraction
46
+ score_match = re.search(r"[-+]?\d*\.\d+", response[-20:])
47
+ score = score_match.group(0) if score_match else "N/A"
48
+
49
+ full_response = response + f"\n\nSentiment Score: {score}"
50
+ return full_response
51
+
52
+ # ChatGPT-style UI
53
+ with gr.Blocks(theme=gr.themes.Soft(), title="Crypto News Summarizer") as demo:
54
+ gr.Markdown("# πŸš€ Crypto News Summarizer + Sentiment Analyzer\nFine-tuned Llama 3.1 8B by @Quanttum")
55
+
56
+ chatbot = gr.ChatInterface(
57
  chat,
58
  examples=[
59
+ ["Bitcoin ETF inflows hit $1.5B this week as institutional adoption surges."],
60
+ ["Mt. Gox starts repaying creditors in BTC β€” 140k coins incoming."],
61
  ["SEC approves spot Ethereum ETF!"],
62
+ ["China just banned all crypto trading again."],
63
  ],
64
+ title=None,
65
+ description="Paste any crypto news or tweet β†’ get instant TL;DR + sentiment score (-1.0 to +1.0)",
66
  cache_examples=True,
67
  )
68