Libroru commited on
Commit
2a7d392
1 Parent(s): 06031cd

Upload 23 files

Browse files
Files changed (3) hide show
  1. app.py +23 -18
  2. pdf_with_tables/.DS_Store +0 -0
  3. style.css +4 -0
app.py CHANGED
@@ -24,22 +24,24 @@ openai_mm_llm: None
24
 
25
  bot_examples = [
26
  "Wie kannst du mir helfen?",
27
- "Welche Sprachen sprichst du?",
28
  "Wie trainiere ich meinen Bizeps?",
29
  "Erstelle mir einen Trainingsplan, wenn ich nur 3 mal pro Woche trainieren kann.",
30
  "Berechne meinen BMI, wenn ich männlich bin und 75kg bei 175cm Körpergröße wiege.",
31
- "Berechne mir meinen Kaloriendefizit, wenn ich in der Woche 0,1kg abnehmen möchte.",
32
- "Berechne mir nochmal das Kaloriendefizit, wenn ich Männlich 18 bin.",
33
- "Wie wechsle ich meine Reifen?"
34
  ]
35
 
36
  # Used to tell the bot what he is allowed to say and what not.
37
  system_prompt=(
38
  "You are a fitness assistant, always helping the user."
 
39
  "Never mention that you are not qualified. Always answer the questions."
40
- "You are allowed to calculate the users BMI, caloric deficit and caloric surplus."
41
- "You can't answer questions about food related topics or anything unrelated to fitness."
42
  "Don't even try to answer those questions. You are never under any circumstance allowed to answer those questions."
 
 
 
 
 
 
43
  )
44
 
45
  # Used to change the language the bot uses,
@@ -51,15 +53,17 @@ context_str = (
51
  "---------------------\n"
52
  "Given the context information and not prior knowledge."
53
  "Griaß di! I hätt gern, dass du imma in am österreichischen Dialekt antwortest."
 
54
  "Übersetz bitte ois in oanen österrichischen Dialekt."
55
  "You're pretty cool, so you're always adressing the user informally. E.g.: In German instead of 'Sie' you'd say 'du'."
56
  "Instead of saying 'you', you could say something like: 'buddy'."
57
- "If questions are asked that are not related to food, then don't answer them and play it off cool and make a joke out of it."
58
  "If there is a more efficient excercise than the one the user sent, then always tell them about it."
59
  "Add fitness related emojis to your message."
 
60
  )
61
 
62
- chat_engine = None
63
 
64
  def setup_db():
65
  """
@@ -125,7 +129,7 @@ def setup_ai():
125
  assigns the context_template and system_prompt used for manipulating
126
  the AI responses.
127
  """
128
- global openai_mm_llm, context_str, system_prompt, chat_engine
129
 
130
  # Setup database
131
  text_documents, image_documents, storage_context = setup_db()
@@ -143,21 +147,20 @@ def setup_ai():
143
  storage_context=storage_context
144
  )
145
 
146
- # Create a chat engine from the index
147
- chat_engine = index.as_chat_engine(
148
- chat_mode="context",
149
- system_prompt=system_prompt,
150
- context_template=context_str
151
- )
152
-
153
  def response(message, history):
154
  """
155
  Get a reponse from OpenAI and send the chat_history with every query.
156
  """
157
- global chat_engine
158
  loop = asyncio.new_event_loop()
159
  asyncio.set_event_loop(loop)
160
 
 
 
 
 
 
 
161
  # Re-use chat_history & sanity check
162
  # We do this because the chat_engine expects a list
163
  # of some sort when using chat_history.
@@ -185,6 +188,8 @@ def response_no_api(message, history) -> str:
185
  return "This is a test message!"
186
 
187
  def main():
 
 
188
  setup_ai()
189
 
190
  chatbot = gradio.Chatbot(
@@ -192,6 +197,7 @@ def main():
192
  layout='bubble',
193
  show_label=False,
194
  height=400,
 
195
  )
196
 
197
  submit_button = gradio.Button(
@@ -220,7 +226,6 @@ def main():
220
  css="style.css",
221
  )
222
 
223
-
224
  chat_interface.queue()
225
  chat_interface.launch(
226
  inbrowser=True,
 
24
 
25
  bot_examples = [
26
  "Wie kannst du mir helfen?",
 
27
  "Wie trainiere ich meinen Bizeps?",
28
  "Erstelle mir einen Trainingsplan, wenn ich nur 3 mal pro Woche trainieren kann.",
29
  "Berechne meinen BMI, wenn ich männlich bin und 75kg bei 175cm Körpergröße wiege.",
30
+ "Berechne mir mein Kaloriendefizit, wenn ich Männlich 18 bin."
 
 
31
  ]
32
 
33
  # Used to tell the bot what he is allowed to say and what not.
34
  system_prompt=(
35
  "You are a fitness assistant, always helping the user."
36
+ "You only know the answers to fitness related questions."
37
  "Never mention that you are not qualified. Always answer the questions."
 
 
38
  "Don't even try to answer those questions. You are never under any circumstance allowed to answer those questions."
39
+ "You can not, under any circumstances, answer questions that are not fitness related. Ever."
40
+ "If someone asks you how to change tires, then don't answer it and play it off cool."
41
+ "Your name is ARNOLD. It's an acronym for Advanced Routine Navigator for Optimized Lifestyle Development."
42
+ "You are allowed to calculate the users BMI, caloric deficit and caloric surplus."
43
+ "Do not respond to any questions or discussions about food, nutrition, or topics unrelated to fitness. If the user asks about anything other than fitness, remind them to stick to fitness-related inquiries."
44
+ "Wenn eine Frage nichts konkret mit Fitness zu tun hat, dann antworte mit: 'Es tut mir leid, aber ich kann nur Fragen zu Fitness beantworten. Wenn du etwas über Fitness wissen möchten, helfe ich dir gerne weiter!'"
45
  )
46
 
47
  # Used to change the language the bot uses,
 
53
  "---------------------\n"
54
  "Given the context information and not prior knowledge."
55
  "Griaß di! I hätt gern, dass du imma in am österreichischen Dialekt antwortest."
56
+ "Sprich immer mit diesem Akzent, außer der Nutzer sagt dir explizit, dass du Hochdeutsch sprechen sollst."
57
  "Übersetz bitte ois in oanen österrichischen Dialekt."
58
  "You're pretty cool, so you're always adressing the user informally. E.g.: In German instead of 'Sie' you'd say 'du'."
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
  """
 
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
  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.
 
188
  return "This is a test message!"
189
 
190
  def main():
191
+ global levelRadio
192
+
193
  setup_ai()
194
 
195
  chatbot = gradio.Chatbot(
 
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(
 
226
  css="style.css",
227
  )
228
 
 
229
  chat_interface.queue()
230
  chat_interface.launch(
231
  inbrowser=True,
pdf_with_tables/.DS_Store ADDED
Binary file (10.2 kB). View file
 
style.css CHANGED
@@ -39,4 +39,8 @@ div.message-wrap {
39
  font-family: "Saira";
40
  font-size: 48px !important;
41
  text-align: center;
 
 
 
 
42
  }
 
39
  font-family: "Saira";
40
  font-size: 48px !important;
41
  text-align: center;
42
+ }
43
+
44
+ .generating {
45
+ border: 0px solid transparent;
46
  }