haxerwddle commited on
Commit
e4811e0
·
1 Parent(s): bfc03bd

Model prompt change

Browse files
Files changed (1) hide show
  1. app.py +14 -8
app.py CHANGED
@@ -1,9 +1,3 @@
1
- import asyncio
2
- try:
3
- asyncio.get_event_loop()
4
- except RuntimeError:
5
- asyncio.set_event_loop(asyncio.new_event_loop())
6
-
7
  import gradio as gr
8
  import torch
9
  from transformers import (
@@ -12,7 +6,6 @@ from transformers import (
12
  T5ForConditionalGeneration,
13
  pipeline
14
  )
15
-
16
  # ------------------ LOAD CLASSIFIER ------------------
17
  cls_model_name = "yangy50/garbage-classification"
18
  classifier = pipeline("image-classification", model=cls_model_name)
@@ -44,6 +37,18 @@ pipe = pipeline(
44
  max_new_tokens=200
45
  )
46
 
 
 
 
 
 
 
 
 
 
 
 
 
47
  def explain_recycling(class_label):
48
  system_msg = {
49
  "role": "system",
@@ -74,7 +79,8 @@ def explain_recycling(class_label):
74
  top_p=0.9
75
  )
76
 
77
- return outputs[0]["generated_text"]
 
78
 
79
 
80
  # ------------------ PIPELINE ------------------
 
 
 
 
 
 
 
1
  import gradio as gr
2
  import torch
3
  from transformers import (
 
6
  T5ForConditionalGeneration,
7
  pipeline
8
  )
 
9
  # ------------------ LOAD CLASSIFIER ------------------
10
  cls_model_name = "yangy50/garbage-classification"
11
  classifier = pipeline("image-classification", model=cls_model_name)
 
37
  max_new_tokens=200
38
  )
39
 
40
+ def clean_chat_output(full_text):
41
+ # Split at the last assistant tag (TinyLlama uses <|assistant|>)
42
+ if "<|assistant|>" in full_text:
43
+ full_text = full_text.split("<|assistant|>")[-1]
44
+
45
+ # Remove any leftover "Item:" echoes
46
+ lines = full_text.strip().split("\n")
47
+ if lines[0].lower().startswith("item:"):
48
+ lines = lines[1:]
49
+
50
+ return "\n".join(lines).strip()
51
+
52
  def explain_recycling(class_label):
53
  system_msg = {
54
  "role": "system",
 
79
  top_p=0.9
80
  )
81
 
82
+ raw = outputs[0]["generated_text"]
83
+ return clean_chat_output(raw)
84
 
85
 
86
  # ------------------ PIPELINE ------------------