initial commit
Browse files- README.md +1 -1
- app.py +29 -57
- requirements.txt +0 -1
README.md
CHANGED
|
@@ -1,5 +1,5 @@
|
|
| 1 |
---
|
| 2 |
-
title:
|
| 3 |
emoji: 💬
|
| 4 |
colorFrom: yellow
|
| 5 |
colorTo: purple
|
|
|
|
| 1 |
---
|
| 2 |
+
title: New Space
|
| 3 |
emoji: 💬
|
| 4 |
colorFrom: yellow
|
| 5 |
colorTo: purple
|
app.py
CHANGED
|
@@ -1,64 +1,36 @@
|
|
| 1 |
-
|
| 2 |
-
from huggingface_hub import InferenceClient
|
| 3 |
-
|
| 4 |
-
"""
|
| 5 |
-
For more information on `huggingface_hub` Inference API support, please check the docs: https://huggingface.co/docs/huggingface_hub/v0.22.2/en/guides/inference
|
| 6 |
-
"""
|
| 7 |
-
client = InferenceClient("HuggingFaceH4/zephyr-7b-beta")
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
def respond(
|
| 11 |
-
message,
|
| 12 |
-
history: list[tuple[str, str]],
|
| 13 |
-
system_message,
|
| 14 |
-
max_tokens,
|
| 15 |
-
temperature,
|
| 16 |
-
top_p,
|
| 17 |
-
):
|
| 18 |
-
messages = [{"role": "system", "content": system_message}]
|
| 19 |
-
|
| 20 |
-
for val in history:
|
| 21 |
-
if val[0]:
|
| 22 |
-
messages.append({"role": "user", "content": val[0]})
|
| 23 |
-
if val[1]:
|
| 24 |
-
messages.append({"role": "assistant", "content": val[1]})
|
| 25 |
-
|
| 26 |
-
messages.append({"role": "user", "content": message})
|
| 27 |
-
|
| 28 |
-
response = ""
|
| 29 |
-
|
| 30 |
-
for message in client.chat_completion(
|
| 31 |
-
messages,
|
| 32 |
-
max_tokens=max_tokens,
|
| 33 |
-
stream=True,
|
| 34 |
-
temperature=temperature,
|
| 35 |
-
top_p=top_p,
|
| 36 |
-
):
|
| 37 |
-
token = message.choices[0].delta.content
|
| 38 |
-
|
| 39 |
-
response += token
|
| 40 |
-
yield response
|
| 41 |
|
|
|
|
| 42 |
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 58 |
),
|
| 59 |
],
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 60 |
)
|
| 61 |
-
|
| 62 |
-
|
| 63 |
if __name__ == "__main__":
|
| 64 |
demo.launch()
|
|
|
|
| 1 |
+
from difflib import Differ
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2 |
|
| 3 |
+
import gradio as gr
|
| 4 |
|
| 5 |
+
def diff_texts(text1, text2):
|
| 6 |
+
d = Differ()
|
| 7 |
+
return [
|
| 8 |
+
(token[2:], token[0] if token[0] != " " else None)
|
| 9 |
+
for token in d.compare(text1, text2)
|
| 10 |
+
]
|
| 11 |
+
|
| 12 |
+
demo = gr.Interface(
|
| 13 |
+
diff_texts,
|
| 14 |
+
[
|
| 15 |
+
gr.Textbox(
|
| 16 |
+
label="Text 1",
|
| 17 |
+
info="Initial text",
|
| 18 |
+
lines=3,
|
| 19 |
+
value="The quick brown fox jumped over the lazy dogs.",
|
| 20 |
+
),
|
| 21 |
+
gr.Textbox(
|
| 22 |
+
label="Text 2",
|
| 23 |
+
info="Text to compare",
|
| 24 |
+
lines=3,
|
| 25 |
+
value="The fast brown fox jumps over lazy dogs.",
|
| 26 |
),
|
| 27 |
],
|
| 28 |
+
gr.HighlightedText(
|
| 29 |
+
label="Diff",
|
| 30 |
+
combine_adjacent=True,
|
| 31 |
+
show_legend=True,
|
| 32 |
+
color_map={"+": "red", "-": "green"}),
|
| 33 |
+
theme=gr.themes.Base()
|
| 34 |
)
|
|
|
|
|
|
|
| 35 |
if __name__ == "__main__":
|
| 36 |
demo.launch()
|
requirements.txt
CHANGED
|
@@ -1 +0,0 @@
|
|
| 1 |
-
huggingface_hub==0.25.2
|
|
|
|
|
|