fffiloni commited on
Commit
8ec4292
β€’
1 Parent(s): 2e0ecb2

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +6 -7
app.py CHANGED
@@ -65,7 +65,7 @@ from transformers import pipeline
65
  pipe = pipeline("text-generation", model="HuggingFaceH4/zephyr-7b-beta", torch_dtype=torch.bfloat16, device_map="auto")
66
 
67
  @spaces.GPU(enable_queue=True)
68
- def get_llm_idea(user_prompt):
69
  agent_maker_sys = f'''
70
  Your job is to generate new magic card from an image description.
71
 
@@ -113,16 +113,16 @@ def infer(image_in, cap_type):
113
  elif cap_type == "Literal" :
114
  user_prompt = get_caption_from_kosmos(image_in)
115
 
116
- gr.Info("Building a system according to the image caption ...")
117
- outputs = get_llm_idea(user_prompt)
118
 
119
 
120
  pattern = r'\<\|system\|\>(.*?)\<\|assistant\|\>'
121
  cleaned_text = re.sub(pattern, '', outputs[0]["generated_text"], flags=re.DOTALL)
122
 
123
- print(f"SUGGESTED LLM: {cleaned_text}")
124
 
125
- return user_prompt, cleaned_text.lstrip("\n")
126
 
127
  title = f"Magic Card Generator",
128
  description = f""
@@ -142,7 +142,7 @@ div#component-14 > .gallery > .gallery-item > .container > img {
142
  with gr.Blocks(css=css) as demo:
143
  with gr.Column(elem_id="col-container"):
144
  gr.HTML(f"""
145
- <h2 style="text-align: center;">LLM Agent from a Picture</h2>
146
  <p style="text-align: center;">{description}</p>
147
  """)
148
 
@@ -182,7 +182,6 @@ with gr.Blocks(css=css) as demo:
182
  cap_type
183
  ],
184
  outputs =[
185
- caption,
186
  result
187
  ]
188
  )
 
65
  pipe = pipeline("text-generation", model="HuggingFaceH4/zephyr-7b-beta", torch_dtype=torch.bfloat16, device_map="auto")
66
 
67
  @spaces.GPU(enable_queue=True)
68
+ def get_card_idea(user_prompt):
69
  agent_maker_sys = f'''
70
  Your job is to generate new magic card from an image description.
71
 
 
113
  elif cap_type == "Literal" :
114
  user_prompt = get_caption_from_kosmos(image_in)
115
 
116
+ gr.Info("Building a new card according to the image caption ...")
117
+ outputs = get_card_idea(user_prompt)
118
 
119
 
120
  pattern = r'\<\|system\|\>(.*?)\<\|assistant\|\>'
121
  cleaned_text = re.sub(pattern, '', outputs[0]["generated_text"], flags=re.DOTALL)
122
 
123
+ print(f"SUGGESTED CARD: {cleaned_text}")
124
 
125
+ return cleaned_text.lstrip("\n")
126
 
127
  title = f"Magic Card Generator",
128
  description = f""
 
142
  with gr.Blocks(css=css) as demo:
143
  with gr.Column(elem_id="col-container"):
144
  gr.HTML(f"""
145
+ <h2 style="text-align: center;">Magic Card Generator</h2>
146
  <p style="text-align: center;">{description}</p>
147
  """)
148
 
 
182
  cap_type
183
  ],
184
  outputs =[
 
185
  result
186
  ]
187
  )