lewtun HF staff commited on
Commit
62373e8
1 Parent(s): b85d14b

Format HTML

Browse files
Files changed (1) hide show
  1. app.py +15 -2
app.py CHANGED
@@ -1,6 +1,7 @@
1
  import datetime
2
  import json
3
  import os
 
4
  import shutil
5
 
6
  import gradio as gr
@@ -16,7 +17,7 @@ API_TOKEN = os.environ.get("API_TOKEN", None)
16
 
17
  model2endpoint = {
18
  "starchat-alpha": "https://api-inference.huggingface.co/models/HuggingFaceH4/starcoderbase-finetuned-oasst1",
19
- "starchat-beta": "https://ddimh86h0wqthbhy.us-east-1.aws.endpoints.huggingface.cloud",
20
  }
21
  model_names = list(model2endpoint.keys())
22
 
@@ -72,6 +73,15 @@ def get_total_inputs(inputs, chatbot, preprompt, user_name, assistant_name, sep)
72
  return total_inputs
73
 
74
 
 
 
 
 
 
 
 
 
 
75
  def has_no_history(chatbot, history):
76
  return not chatbot and not history
77
 
@@ -156,7 +166,10 @@ def generate(
156
  else:
157
  history[-1] = output
158
 
159
- chat = [(history[i].strip(), history[i + 1].strip()) for i in range(0, len(history) - 1, 2)]
 
 
 
160
 
161
  yield chat, history, user_message, ""
162
 
 
1
  import datetime
2
  import json
3
  import os
4
+ import re
5
  import shutil
6
 
7
  import gradio as gr
 
17
 
18
  model2endpoint = {
19
  "starchat-alpha": "https://api-inference.huggingface.co/models/HuggingFaceH4/starcoderbase-finetuned-oasst1",
20
+ "starchat-beta": "https://api-inference.huggingface.co/models/HuggingFaceH4/starchat-beta",
21
  }
22
  model_names = list(model2endpoint.keys())
23
 
 
73
  return total_inputs
74
 
75
 
76
+ def wrap_html_code(text):
77
+ pattern = r"<.*?>"
78
+ matches = re.findall(pattern, text)
79
+ if len(matches) > 0:
80
+ return f"```{text}```"
81
+ else:
82
+ return text
83
+
84
+
85
  def has_no_history(chatbot, history):
86
  return not chatbot and not history
87
 
 
166
  else:
167
  history[-1] = output
168
 
169
+ chat = [
170
+ (wrap_html_code(history[i].strip()), wrap_html_code(history[i + 1].strip()))
171
+ for i in range(0, len(history) - 1, 2)
172
+ ]
173
 
174
  yield chat, history, user_message, ""
175