Spaces:
Runtime error
Runtime error
Delete app.py
Browse files
app.py
DELETED
|
@@ -1,20 +0,0 @@
|
|
| 1 |
-
import gradio as gr
|
| 2 |
-
from pygments import highlight
|
| 3 |
-
from pygments.lexers import get_lexer_by_name
|
| 4 |
-
from pygments.formatters import HtmlFormatter
|
| 5 |
-
|
| 6 |
-
def highlight_code(code, language):
|
| 7 |
-
lexer = get_lexer_by_name(language, stripall=True)
|
| 8 |
-
formatter = HtmlFormatter()
|
| 9 |
-
return highlight(code, lexer, formatter)
|
| 10 |
-
|
| 11 |
-
def chatbot(text):
|
| 12 |
-
code = text
|
| 13 |
-
html_code = highlight_code(code, ‘python’)
|
| 14 |
-
return html_code
|
| 15 |
-
|
| 16 |
-
gr.chatbot(fn=chatbot, title=“代码高亮示例”, bot_avatar=“https://gradio.app/static/img/logo.png”, layout=“vertical”, examples=[
|
| 17 |
-
[“def generate_numbers(n):”, " for i in range(n):“, " yield(i+1)”],
|
| 18 |
-
[“def sum_numbers(n):”, " return sum(generate_numbers(n))"]
|
| 19 |
-
],
|
| 20 |
-
debug=True)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|