MojoHz commited on
Commit
06d8dfd
·
verified ·
1 Parent(s): 1c53851

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +45 -30
app.py CHANGED
@@ -1,11 +1,5 @@
1
- !pip install transformers torch gradio
2
 
3
- # prompt: code to login to hugging face
4
 
5
- import os
6
- from huggingface_hub import notebook_login
7
-
8
- notebook_login()
9
 
10
  import torch
11
  from transformers import AutoTokenizer, AutoModelForCausalLM
@@ -108,56 +102,77 @@ def generate_custom_caption(day, task):
108
  caption = caption[len(prompt):].strip()
109
  return caption
110
 
111
- # Gradio Interface function to handle marketing schedule and captions, with conversation
112
  def gradio_interface(user_prompt):
113
  conversation = []
114
 
115
  # Generate the marketing schedule
116
- conversation.append("Hassan - Marketing Dept.: I'm processing your request. Please wait a moment...")
117
- yield "\n".join(conversation) # Update the interface step by step
118
 
119
  schedule = generate_marketing_schedule(user_prompt)
120
 
121
  if isinstance(schedule, dict):
122
- conversation.append("Hassan - Marketing Dept.: I have created the marketing schedule based on the user's request.")
123
- yield "\n".join(conversation) # Update the interface with schedule processing
124
 
125
- # Add some pause to simulate conversation
126
  time.sleep(2)
127
 
128
- conversation.append("Hassan Marketing Dept.: Let's now consult the Caption Generator to create captions for each day.")
129
- yield "\n".join(conversation) # Update the interface with new dialogue
130
 
131
- # For each day in the schedule, generate a caption
132
  captions = {}
133
  for day, task in schedule.items():
134
- conversation.append(f"Hassan Marketing Dept.: For {day}, the task is '{task}'. Caption Generator, can you create a caption?")
135
- yield "\n".join(conversation) # Update the interface with the conversation
136
 
137
- time.sleep(2) # Simulate the time taken by the caption generator
138
 
139
  caption = generate_custom_caption(day, task)
140
  captions[day] = caption
141
 
142
- conversation.append(f"Ahmed - Media Dept.: Here's the caption for {day}: '{caption}'")
143
- yield "\n".join(conversation) # Update the interface with the caption for the day
144
 
145
- # Final output
146
- conversation.append("Hassan - Marketing Dept.: The final marketing schedule with captions is ready.")
147
- yield "\n".join(conversation) # Final update
148
 
149
  else:
150
  yield schedule # If there was an error, just return the error message
151
 
152
- # Launch Gradio interface
 
153
  interface = gr.Interface(
154
  fn=gradio_interface,
155
- inputs=gr.Textbox(label="Enter Your Marketing Prompt", placeholder="e.g., Campaign for a new hoodie release."),
156
- outputs=gr.Textbox(label="Generated Marketing Schedule & Captions"),
157
- title="AI Marketing Schedule and Captions Generator",
158
- description="Type a description of your campaign to get a tailored weekly marketing schedule and social media captions.",
159
- allow_flagging="never", # Prevent flagging issues
160
- theme="huggingface" # Use Hugging Face theme
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
161
  )
162
 
163
  interface.launch()
 
 
1
 
 
2
 
 
 
 
 
3
 
4
  import torch
5
  from transformers import AutoTokenizer, AutoModelForCausalLM
 
102
  caption = caption[len(prompt):].strip()
103
  return caption
104
 
 
105
  def gradio_interface(user_prompt):
106
  conversation = []
107
 
108
  # Generate the marketing schedule
109
+ conversation.append('<span style="color: #3498db; font-weight: bold;">Hassan - Marketing Dept.:</span> I\'m processing your request. Please wait a moment...')
110
+ yield "<br>".join(conversation) # Update the interface with each message on a new line
111
 
112
  schedule = generate_marketing_schedule(user_prompt)
113
 
114
  if isinstance(schedule, dict):
115
+ conversation.append('<span style="color: #3498db; font-weight: bold;">Hassan - Marketing Dept.:</span> I have created the marketing schedule based on your request.')
116
+ yield "<br>".join(conversation) # Update the interface with schedule processing
117
 
 
118
  time.sleep(2)
119
 
120
+ conversation.append('<span style="color: #3498db; font-weight: bold;">Hassan - Marketing Dept.:</span> Let\'s now consult the Caption Generator to create captions for each day.')
121
+ yield "<br>".join(conversation) # Update the interface with new dialogue
122
 
 
123
  captions = {}
124
  for day, task in schedule.items():
125
+ conversation.append(f'<span style="color: #3498db; font-weight: bold;">Hassan - Marketing Dept.:</span> For <strong>{day}</strong>, the task is <em>\'{task}\'</em>. Caption Generator, can you create a caption?')
126
+ yield "<br>".join(conversation) # Update the interface with the conversation
127
 
128
+ time.sleep(2)
129
 
130
  caption = generate_custom_caption(day, task)
131
  captions[day] = caption
132
 
133
+ conversation.append(f'<span style="color: #e74c3c; font-weight: bold;">Ahmed - Media Dept.:</span> Here\'s the caption for <strong>{day}</strong>: <em>\'{caption}\'</em>')
134
+ yield "<br>".join(conversation) # Update the interface with the caption for the day
135
 
136
+ conversation.append('<span style="color: #3498db; font-weight: bold;">Hassan - Marketing Dept.:</span> The final marketing schedule with captions is ready.')
137
+ yield "<br>".join(conversation) # Final update
 
138
 
139
  else:
140
  yield schedule # If there was an error, just return the error message
141
 
142
+
143
+ # Launch Gradio interface with improved design
144
  interface = gr.Interface(
145
  fn=gradio_interface,
146
+ inputs=gr.Textbox(label="Enter Your Marketing Prompt", placeholder="e.g., Campaign for a new hoodie release.", lines=2),
147
+ outputs=gr.Markdown(label="Generated Marketing Schedule & Captions"), # Changed this to Markdown
148
+ title=" laibor Marketing Demo ",
149
+ description="🧑‍💻 Enter a campaign description to generate a weekly marketing schedule with captions tailored to your brand.",
150
+ theme="compact", # Sleek compact theme
151
+ css="""
152
+ .gradio-container {
153
+ background-color: #000000;
154
+ color: white;
155
+ font-family: 'Arial', sans-serif;
156
+ border-radius: 10px;
157
+ border: 2px solid #dee2e6;
158
+ }
159
+ .gr-button {
160
+ background-color: #4CAF50;
161
+ color: white;
162
+ font-size: 16px;
163
+ font-weight: bold;
164
+ }
165
+ .gr-textbox, .gr-markdown {
166
+ background-color: #333333;
167
+ color: white;
168
+ border: 1px solid #555555;
169
+ border-radius: 8px;
170
+ }
171
+ .gr-textbox input, .gr-markdown textarea {
172
+ background-color: #333333;
173
+ color: white;
174
+ }
175
+ """
176
  )
177
 
178
  interface.launch()