Libroru commited on
Commit
33128bc
1 Parent(s): 1302993

Upload 23 files

Browse files
Files changed (3) hide show
  1. app.py +17 -13
  2. pdf_with_tables/.DS_Store +0 -0
  3. style.css +8 -4
app.py CHANGED
@@ -59,11 +59,11 @@ context_str = (
59
  "Instead of saying 'you', you could say something like: 'buddy'."
60
  "If questions are asked that are not related to fitness, then don't answer them and play it off cool and make a joke out of it."
61
  "If there is a more efficient excercise than the one the user sent, then always tell them about it."
62
- "Add fitness related emojis to your message."
63
- "If someone asks you how to change tires, then don't answer it and play it off cool."
64
  )
65
 
66
- index = None
67
 
68
  def setup_db():
69
  """
@@ -95,6 +95,8 @@ def setup_db():
95
 
96
  # Crop images to tables
97
  for image in os.listdir("./table_images"):
 
 
98
  detect_and_crop_save_table("./table_images/"+image)
99
  # Delete old uncropped image
100
  os.remove("./table_images/"+image)
@@ -129,7 +131,7 @@ def setup_ai():
129
  assigns the context_template and system_prompt used for manipulating
130
  the AI responses.
131
  """
132
- global openai_mm_llm, context_str, system_prompt, index
133
 
134
  # Setup database
135
  text_documents, image_documents, storage_context = setup_db()
@@ -147,20 +149,22 @@ def setup_ai():
147
  storage_context=storage_context
148
  )
149
 
 
 
 
 
 
 
 
150
  def response(message, history):
151
  """
152
  Get a reponse from OpenAI and send the chat_history with every query.
153
  """
154
- global index
155
  loop = asyncio.new_event_loop()
156
  asyncio.set_event_loop(loop)
157
 
158
- # Create a chat engine from the index
159
- chat_engine = index.as_chat_engine(
160
- chat_mode="context",
161
- system_prompt=system_prompt,
162
- context_template=context_str
163
- )
164
  # Re-use chat_history & sanity check
165
  # We do this because the chat_engine expects a list
166
  # of some sort when using chat_history.
@@ -196,12 +200,12 @@ def main():
196
  avatar_images=("user_avatar.png", "chatbot_avatar.png"),
197
  layout='bubble',
198
  show_label=False,
199
- height=400,
200
  value=[[None, "Griaß di, i bin da Arnold, dei Fitness-Chatbot. I gfrei mi, dass du di für dei Gsundheit und dein Leib interessierst. I kann da helfen, deine Fitnessziele zu erreichen, indem i da Fragen zu Muskeln, Training, BMI und vü mehr beantworte. Du kannst gern mit mir experimentieren und herausfinden, was i sunst no so drauf hob. I bin immer bereit, da zu helfen. Wos wüst wissen? 💪🏋️💬"]]
201
  )
202
 
203
  submit_button = gradio.Button(
204
- value="Ask Arnold",
205
  elem_classes=["ask-button"],
206
  )
207
 
 
59
  "Instead of saying 'you', you could say something like: 'buddy'."
60
  "If questions are asked that are not related to fitness, then don't answer them and play it off cool and make a joke out of it."
61
  "If there is a more efficient excercise than the one the user sent, then always tell them about it."
62
+ "Add fitness related emojis to the end of your message."
63
+ "Fang deine Sätze immer wieder anders an und grüße den Nutzer nicht. Niemals.."
64
  )
65
 
66
+ chat_engine = None
67
 
68
  def setup_db():
69
  """
 
95
 
96
  # Crop images to tables
97
  for image in os.listdir("./table_images"):
98
+ if image.startswith('.DS_'):
99
+ continue
100
  detect_and_crop_save_table("./table_images/"+image)
101
  # Delete old uncropped image
102
  os.remove("./table_images/"+image)
 
131
  assigns the context_template and system_prompt used for manipulating
132
  the AI responses.
133
  """
134
+ global openai_mm_llm, context_str, system_prompt, chat_engine
135
 
136
  # Setup database
137
  text_documents, image_documents, storage_context = setup_db()
 
149
  storage_context=storage_context
150
  )
151
 
152
+ # Create a chat engine from the index
153
+ chat_engine = index.as_chat_engine(
154
+ chat_mode="context",
155
+ system_prompt=system_prompt,
156
+ context_template=context_str
157
+ )
158
+
159
  def response(message, history):
160
  """
161
  Get a reponse from OpenAI and send the chat_history with every query.
162
  """
163
+ global chat_engine
164
  loop = asyncio.new_event_loop()
165
  asyncio.set_event_loop(loop)
166
 
167
+
 
 
 
 
 
168
  # Re-use chat_history & sanity check
169
  # We do this because the chat_engine expects a list
170
  # of some sort when using chat_history.
 
200
  avatar_images=("user_avatar.png", "chatbot_avatar.png"),
201
  layout='bubble',
202
  show_label=False,
203
+ height=500,
204
  value=[[None, "Griaß di, i bin da Arnold, dei Fitness-Chatbot. I gfrei mi, dass du di für dei Gsundheit und dein Leib interessierst. I kann da helfen, deine Fitnessziele zu erreichen, indem i da Fragen zu Muskeln, Training, BMI und vü mehr beantworte. Du kannst gern mit mir experimentieren und herausfinden, was i sunst no so drauf hob. I bin immer bereit, da zu helfen. Wos wüst wissen? 💪🏋️💬"]]
205
  )
206
 
207
  submit_button = gradio.Button(
208
+ value="ASK ARNOLD",
209
  elem_classes=["ask-button"],
210
  )
211
 
pdf_with_tables/.DS_Store ADDED
Binary file (10.2 kB). View file
 
style.css CHANGED
@@ -22,13 +22,17 @@ div.gap.panel>div.gr-group {
22
  }
23
 
24
  .ask-button {
25
- background-color: var(--color-accent);
 
26
  font-weight: bold;
27
  letter-spacing: 0.1rem;
28
  }
29
 
30
  .gallery-item {
31
- color: var(--block-label-text-color) !important
 
 
 
32
  }
33
 
34
  div.message-wrap {
@@ -41,6 +45,6 @@ div.message-wrap {
41
  text-align: center;
42
  }
43
 
44
- .generating {
45
- border: 0px solid transparent;
46
  }
 
22
  }
23
 
24
  .ask-button {
25
+ /*background-color: var(--color-accent);*/
26
+ background-color: #5fb0ab !important;
27
  font-weight: bold;
28
  letter-spacing: 0.1rem;
29
  }
30
 
31
  .gallery-item {
32
+ color: var(--block-label-text-color) !important;
33
+ border: 1px var(--block-border-color) solid !important;
34
+ padding: 2px !important;
35
+ margin: 2px !important;
36
  }
37
 
38
  div.message-wrap {
 
45
  text-align: center;
46
  }
47
 
48
+ div.generating {
49
+ border: none !important;
50
  }