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

UI change

Browse files
Files changed (1) hide show
  1. app.py +16 -4
app.py CHANGED
@@ -5,6 +5,7 @@ except RuntimeError:
5
  asyncio.set_event_loop(asyncio.new_event_loop())
6
 
7
  import gradio as gr
 
8
  from transformers import (
9
  AutoTokenizer, AutoModelForCausalLM,
10
  T5Tokenizer,
@@ -28,9 +29,20 @@ def classify_image(image):
28
 
29
 
30
  # ------------------ LOAD CHAT MODEL ------------------
31
- model_name = "TinyLlama/TinyLlama-1.1B-Chat-v1.0"
32
- tokenizer = AutoTokenizer.from_pretrained(model_name)
33
- chat_model = AutoModelForCausalLM.from_pretrained(model_name)
 
 
 
 
 
 
 
 
 
 
 
34
 
35
  def explain_recycling(class_label):
36
  system_msg = {
@@ -55,7 +67,7 @@ def explain_recycling(class_label):
55
  add_generation_prompt=True
56
  )
57
 
58
- outputs = chat_model.generate(
59
  prompt,
60
  do_sample=True,
61
  temperature=0.3,
 
5
  asyncio.set_event_loop(asyncio.new_event_loop())
6
 
7
  import gradio as gr
8
+ import torch
9
  from transformers import (
10
  AutoTokenizer, AutoModelForCausalLM,
11
  T5Tokenizer,
 
29
 
30
 
31
  # ------------------ LOAD CHAT MODEL ------------------
32
+ tiny_model = "TinyLlama/TinyLlama-1.1B-Chat-v1.0"
33
+
34
+ tokenizer = AutoTokenizer.from_pretrained(tiny_model)
35
+ chat_model = AutoModelForCausalLM.from_pretrained(
36
+ tiny_model,
37
+ torch_dtype=torch.float32)
38
+
39
+ pipe = pipeline(
40
+ "text-generation",
41
+ model=chat_model,
42
+ tokenizer=tokenizer,
43
+ device_map="auto",
44
+ max_new_tokens=200
45
+ )
46
 
47
  def explain_recycling(class_label):
48
  system_msg = {
 
67
  add_generation_prompt=True
68
  )
69
 
70
+ outputs = pipe(
71
  prompt,
72
  do_sample=True,
73
  temperature=0.3,