Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -3,9 +3,9 @@ import gradio as gr
|
|
| 3 |
import openai
|
| 4 |
import os
|
| 5 |
import sys
|
| 6 |
-
import traceback
|
| 7 |
|
| 8 |
-
# import
|
|
|
|
| 9 |
|
| 10 |
my_api_key = "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" # 在这里输入你的 API 密钥
|
| 11 |
initial_prompt = "You are a helpful assistant."
|
|
@@ -26,6 +26,7 @@ else:
|
|
| 26 |
|
| 27 |
def parse_text(text):
|
| 28 |
in_code = False
|
|
|
|
| 29 |
lines = text.split("\n")
|
| 30 |
for i, line in enumerate(lines):
|
| 31 |
if "```" in line:
|
|
@@ -46,6 +47,7 @@ def parse_text(text):
|
|
| 46 |
line = line.replace("。", ".")
|
| 47 |
line = line.replace("‘", "'")
|
| 48 |
line = line.replace("“", ' " ')
|
|
|
|
| 49 |
return "".join(lines)
|
| 50 |
|
| 51 |
|
|
@@ -66,7 +68,11 @@ def get_response(system, context, myKey, raw=False):
|
|
| 66 |
message_with_stats = f"{message}\n\n================\n\n{statistics}"
|
| 67 |
# message_with_stats = markdown.markdown(message_with_stats)
|
| 68 |
|
| 69 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 70 |
|
| 71 |
|
| 72 |
def predict(chatbot, input_sentence, system, context, myKey):
|
|
@@ -327,6 +333,7 @@ with gr.Blocks() as demo:
|
|
| 327 |
)
|
| 328 |
|
| 329 |
|
| 330 |
-
|
| 331 |
demo.title = "ChatGPT 🚀"
|
| 332 |
-
demo.queue().launch(
|
|
|
|
|
|
|
|
|
| 3 |
import openai
|
| 4 |
import os
|
| 5 |
import sys
|
|
|
|
| 6 |
|
| 7 |
+
# import traceback
|
| 8 |
+
import markdown
|
| 9 |
|
| 10 |
my_api_key = "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" # 在这里输入你的 API 密钥
|
| 11 |
initial_prompt = "You are a helpful assistant."
|
|
|
|
| 26 |
|
| 27 |
def parse_text(text):
|
| 28 |
in_code = False
|
| 29 |
+
|
| 30 |
lines = text.split("\n")
|
| 31 |
for i, line in enumerate(lines):
|
| 32 |
if "```" in line:
|
|
|
|
| 47 |
line = line.replace("。", ".")
|
| 48 |
line = line.replace("‘", "'")
|
| 49 |
line = line.replace("“", ' " ')
|
| 50 |
+
|
| 51 |
return "".join(lines)
|
| 52 |
|
| 53 |
|
|
|
|
| 68 |
message_with_stats = f"{message}\n\n================\n\n{statistics}"
|
| 69 |
# message_with_stats = markdown.markdown(message_with_stats)
|
| 70 |
|
| 71 |
+
message_with_stats = markdown.markdown(
|
| 72 |
+
message_with_stats, extensions=["fenced_code", "codehilite"]
|
| 73 |
+
)
|
| 74 |
+
# return message, parse_text(message_with_stats)
|
| 75 |
+
return message, message_with_stats
|
| 76 |
|
| 77 |
|
| 78 |
def predict(chatbot, input_sentence, system, context, myKey):
|
|
|
|
| 333 |
)
|
| 334 |
|
| 335 |
|
|
|
|
| 336 |
demo.title = "ChatGPT 🚀"
|
| 337 |
+
demo.queue(concurrency_count=5).launch(
|
| 338 |
+
server_name="0.0.0.0", share=False
|
| 339 |
+
) # 改为 share=True 可以创建公开分享链接
|