aliabd commited on
Commit
09d1e2a
·
1 Parent(s): 066c366

Upload folder using huggingface_hub

Browse files
Files changed (4) hide show
  1. README.md +8 -8
  2. run.ipynb +1 -0
  3. run.py +38 -0
  4. screenshot.png +0 -0
README.md CHANGED
@@ -1,12 +1,12 @@
 
1
  ---
2
- title: Diff Texts 3-x
3
- emoji:
4
- colorFrom: purple
5
- colorTo: red
6
  sdk: gradio
7
- sdk_version: 4.3.0
8
- app_file: app.py
9
  pinned: false
 
10
  ---
11
-
12
- Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
 
1
+
2
  ---
3
+ title: diff_texts_3-x
4
+ emoji: 🔥
5
+ colorFrom: indigo
6
+ colorTo: indigo
7
  sdk: gradio
8
+ sdk_version: 3.50.1
9
+ app_file: run.py
10
  pinned: false
11
+ hf_oauth: true
12
  ---
 
 
run.ipynb ADDED
@@ -0,0 +1 @@
 
 
1
+ {"cells": [{"cell_type": "markdown", "id": "302934307671667531413257853548643485645", "metadata": {}, "source": ["# Gradio Demo: diff_texts"]}, {"cell_type": "code", "execution_count": null, "id": "272996653310673477252411125948039410165", "metadata": {}, "outputs": [], "source": ["!pip install -q gradio "]}, {"cell_type": "code", "execution_count": null, "id": "288918539441861185822528903084949547379", "metadata": {}, "outputs": [], "source": ["from difflib import Differ\n", "\n", "import gradio as gr\n", "\n", "\n", "def diff_texts(text1, text2):\n", " d = Differ()\n", " return [\n", " (token[2:], token[0] if token[0] != \" \" else None)\n", " for token in d.compare(text1, text2)\n", " ]\n", "\n", "\n", "demo = gr.Interface(\n", " diff_texts,\n", " [\n", " gr.Textbox(\n", " label=\"Text 1\",\n", " info=\"Initial text\",\n", " lines=3,\n", " value=\"The quick brown fox jumped over the lazy dogs.\",\n", " ),\n", " gr.Textbox(\n", " label=\"Text 2\",\n", " info=\"Text to compare\",\n", " lines=3,\n", " value=\"The fast brown fox jumps over lazy dogs.\",\n", " ),\n", " ],\n", " gr.HighlightedText(\n", " label=\"Diff\",\n", " combine_adjacent=True,\n", " show_legend=True,\n", " color_map={\"+\": \"red\", \"-\": \"green\"}),\n", " theme=gr.themes.Base()\n", ")\n", "if __name__ == \"__main__\":\n", " demo.launch()\n"]}], "metadata": {}, "nbformat": 4, "nbformat_minor": 5}
run.py ADDED
@@ -0,0 +1,38 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from difflib import Differ
2
+
3
+ import gradio as gr
4
+
5
+
6
+ def diff_texts(text1, text2):
7
+ d = Differ()
8
+ return [
9
+ (token[2:], token[0] if token[0] != " " else None)
10
+ for token in d.compare(text1, text2)
11
+ ]
12
+
13
+
14
+ demo = gr.Interface(
15
+ diff_texts,
16
+ [
17
+ gr.Textbox(
18
+ label="Text 1",
19
+ info="Initial text",
20
+ lines=3,
21
+ value="The quick brown fox jumped over the lazy dogs.",
22
+ ),
23
+ gr.Textbox(
24
+ label="Text 2",
25
+ info="Text to compare",
26
+ lines=3,
27
+ value="The fast brown fox jumps over lazy dogs.",
28
+ ),
29
+ ],
30
+ gr.HighlightedText(
31
+ label="Diff",
32
+ combine_adjacent=True,
33
+ show_legend=True,
34
+ color_map={"+": "red", "-": "green"}),
35
+ theme=gr.themes.Base()
36
+ )
37
+ if __name__ == "__main__":
38
+ demo.launch()
screenshot.png ADDED