justinj92 commited on
Commit
deffbd8
1 Parent(s): e0f9a39

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +4 -54
app.py CHANGED
@@ -33,56 +33,6 @@ model = AutoModelForCausalLM.from_pretrained(
33
  trust_remote_code=True
34
  )
35
 
36
- # Chatbot tab function
37
- @spaces.GPU()
38
- def stream_chat(
39
- message: str,
40
- history: list,
41
- system_prompt: str,
42
- temperature: float = 0.8,
43
- max_new_tokens: int = 1024,
44
- top_p: float = 1.0,
45
- top_k: int = 20,
46
- penalty: float = 1.2,
47
- ):
48
- print(f'message: {message}')
49
- print(f'history: {history}')
50
-
51
- conversation = [
52
- {"role": "system", "content": system_prompt}
53
- ]
54
- for prompt, answer in history:
55
- conversation.extend([
56
- {"role": "user", "content": prompt},
57
- {"role": "assistant", "content": answer},
58
- ])
59
-
60
- conversation.append({"role": "user", "content": message})
61
-
62
- input_ids = tokenizer.apply_chat_template(conversation, add_generation_prompt=True, return_tensors="pt").to(model.device)
63
-
64
- streamer = TextIteratorStreamer(tokenizer, timeout=60.0, skip_prompt=True, skip_special_tokens=True)
65
-
66
- generate_kwargs = dict(
67
- input_ids=input_ids,
68
- max_new_tokens = max_new_tokens,
69
- do_sample = False if temperature == 0 else True,
70
- top_p = top_p,
71
- top_k = top_k,
72
- temperature = temperature,
73
- eos_token_id=[128001,128008,128009],
74
- streamer=streamer,
75
- )
76
-
77
- with torch.no_grad():
78
- thread = Thread(target=model.generate, kwargs=generate_kwargs)
79
- thread.start()
80
-
81
- buffer = ""
82
- for new_text in streamer:
83
- buffer += new_text
84
- yield buffer
85
-
86
  # Vision model setup
87
  models = {
88
  "justinj92/phi-35-vision-burberry": AutoModelForCausalLM.from_pretrained("justinj92/phi-35-vision-burberry", trust_remote_code=True, torch_dtype="auto", _attn_implementation="flash_attention_2").cuda().eval()
@@ -184,20 +134,20 @@ footer = """
184
  """
185
 
186
  # Gradio app with two tabs
187
- with gr.Blocks(css=CSS, theme="small_and_pretty") as demo:
188
  gr.HTML(TITLE)
189
  gr.HTML(EXPLANATION)
190
  with gr.Tab("Burberry Vision"):
191
  with gr.Row():
192
- input_img = gr.Image(label="Input Picture")
193
  with gr.Row():
194
  model_selector = gr.Dropdown(choices=list(models.keys()), label="Model", value="justinj92/phi-35-vision-burberry")
195
  # with gr.Row():
196
  # text_input = gr.Textbox(label="Question")
197
  with gr.Row():
198
- submit_btn = gr.Button(value="Submit")
199
  with gr.Row():
200
- output_text = gr.Textbox(label="Output Text")
201
 
202
  submit_btn.click(stream_vision, [input_img, model_selector], [output_text])
203
 
 
33
  trust_remote_code=True
34
  )
35
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
36
  # Vision model setup
37
  models = {
38
  "justinj92/phi-35-vision-burberry": AutoModelForCausalLM.from_pretrained("justinj92/phi-35-vision-burberry", trust_remote_code=True, torch_dtype="auto", _attn_implementation="flash_attention_2").cuda().eval()
 
134
  """
135
 
136
  # Gradio app with two tabs
137
+ with gr.Blocks(css=CSS, theme=gr.themes.Default(primary_hue=gr.themes.colors.red, secondary_hue=gr.themes.colors.pink)) as demo:
138
  gr.HTML(TITLE)
139
  gr.HTML(EXPLANATION)
140
  with gr.Tab("Burberry Vision"):
141
  with gr.Row():
142
+ input_img = gr.Image(label="Upload a Burberry Product Image")
143
  with gr.Row():
144
  model_selector = gr.Dropdown(choices=list(models.keys()), label="Model", value="justinj92/phi-35-vision-burberry")
145
  # with gr.Row():
146
  # text_input = gr.Textbox(label="Question")
147
  with gr.Row():
148
+ submit_btn = gr.Button(value="Tell me about this product")
149
  with gr.Row():
150
+ output_text = gr.Textbox(label="Product Info")
151
 
152
  submit_btn.click(stream_vision, [input_img, model_selector], [output_text])
153