Spaces:
Building
Building
Update app-fanta-backup.py
Browse files- app-fanta-backup.py +34 -80
app-fanta-backup.py
CHANGED
@@ -6,7 +6,7 @@ import os
|
|
6 |
import requests
|
7 |
|
8 |
# ์ถ๋ก API ํด๋ผ์ด์ธํธ ์ค์
|
9 |
-
hf_client = InferenceClient("CohereForAI/c4ai-command-r-plus-08-2024", token=
|
10 |
|
11 |
def respond(
|
12 |
message,
|
@@ -16,62 +16,9 @@ def respond(
|
|
16 |
temperature=0.8,
|
17 |
top_p=0.9,
|
18 |
):
|
19 |
-
|
20 |
system_prefix = """
|
21 |
-
|
22 |
-
|
23 |
-
1) Start by establishing the setting, magical system, and key characters
|
24 |
-
2) Write over 3000 characters of fantasy fiction
|
25 |
-
3) Include vivid descriptions of:
|
26 |
-
- Magical phenomena and systems
|
27 |
-
- Fantastic creatures and beings
|
28 |
-
- Mythical locations and landscapes
|
29 |
-
- Character development and interactions
|
30 |
-
- Epic battles and conflicts
|
31 |
-
- Ancient prophecies and legends
|
32 |
-
Include the following elements as appropriate:
|
33 |
-
- Magic spells and rituals
|
34 |
-
- Mythical creatures (dragons, unicorns, phoenixes)
|
35 |
-
- Magical artifacts and relics
|
36 |
-
- Ancient civilizations and their ruins
|
37 |
-
- Heroic quests and adventures
|
38 |
-
- Political intrigue in fantasy realms
|
39 |
-
- Magical combat and warfare
|
40 |
-
- Prophecies and destinies
|
41 |
-
- Fantasy races (elves, dwarves, etc.)
|
42 |
-
- Mystical powers and abilities
|
43 |
-
- Ancient languages and runes
|
44 |
-
- Supernatural phenomena
|
45 |
-
- Epic battles between good and evil
|
46 |
-
- Character growth and development
|
47 |
-
- World-building details
|
48 |
-
- Cultural elements of fantasy societies
|
49 |
-
- Magical technology and innovations
|
50 |
-
- Religious and spiritual systems
|
51 |
-
- Environmental magic and nature
|
52 |
-
- Legendary weapons and armor
|
53 |
-
Incorporate various fantasy subgenres:
|
54 |
-
- High Fantasy
|
55 |
-
- Dark Fantasy
|
56 |
-
- Sword and Sorcery
|
57 |
-
- Epic Fantasy
|
58 |
-
- Urban Fantasy
|
59 |
-
- Historical Fantasy
|
60 |
-
- Mythic Fantasy
|
61 |
-
์ต๋ํ ๊ธธ๊ฒ 7860 ํ ํฐ๊น์ง ์์ฑํ๋ผ.
|
62 |
-
๋ค์ ์ ์ํ๋ "[์ธ์ฉ๋ฌธ]"์ ์ํฉ์ ๋ง๊ฒ ์ถ๊ฐํ์ฌ ์์ค ์์ฑ์ ๋์ฑ ํ๋ถํ๊ณ ๋ชฐ์
๊ฐ ์๋ ํํ์ ์์ฒญ(์ถ๋ ฅ)๋ฐ์ ์ธ์ด๋ก ํํํ๋ผ.
|
63 |
-
[์ธ์ฉ๋ฌธ]
|
64 |
-
"๊ณ ๋์ ๋ง๋ฒ์ด ๊นจ์ด๋๋ฉฐ ๋์ง๊ฐ ์ธ๋ฆฌ๋ ์๋ฆฌ๊ฐ ๋ค๋ ธ๋ค..."
|
65 |
-
"์ฉ์ ์จ๊ฒฐ์ด ํ๋์ ๊ฐ๋ฅด๋ฉฐ, ๊ตฌ๋ฆ์ ๋ถํ์ ๋ค..."
|
66 |
-
"์ ๋นํ ๋ฃฌ๋ฌธ์๊ฐ ๋น๋๋ฉฐ ๊ณต์ค์ ๋ ์ฌ๋๋ค..."
|
67 |
-
"์ํ๋ค์ ๋
ธ๋๊ฐ ์ฒ์ ์ธ๋ฆฌ์ ๋๋ฌด๋ค์ด ์ถค์ถ๊ธฐ ์์ํ๋ค..."
|
68 |
-
"์์ธ์ ๋ง์์ด ๋ฉ์๋ฆฌ์น๋ฉฐ ์ด๋ช
์ ์ค์ด ์์ง์ด๊ธฐ ์์ํ๋ค..."
|
69 |
-
"๋ง๋ฒ์ฌ์ ์งํก์ด์์ ๋ฒ์ฉ์ด๋ ๋น์ด ์ด๋ ์ ๊ฐ๋ฅด๋ฉฐ..."
|
70 |
-
"๊ณ ๋ ๋์ํ์ ๋์ฅ๊ฐ์์ ์ ์ค์ ๊ฒ์ด ๋ง๋ค์ด์ง๊ณ ์์๋ค..."
|
71 |
-
"์์ ๊ตฌ์ฌ ์์ ๋น์น ๋ฏธ๋์ ํ์์ด ์์ํ ๋ชจ์ต์ ๋๋ฌ๋๋ค..."
|
72 |
-
"์ ์ฑํ ๊ฒฐ๊ณ๊ฐ ๊นจ์ด์ง๋ฉฐ ๋ด์ธ๋ ์
์ด ๊นจ์ด๋ฌ๋ค..."
|
73 |
-
"์์
์ ๋ฐ๊ฑธ์์ด ์ด๋ช
์ ๊ธธ์ ๋ฐ๋ผ ์ธ๋ ค ํผ์ก๋ค..."
|
74 |
-
"""
|
75 |
|
76 |
messages = [{"role": "system", "content": f"{system_prefix} {system_message}"}]
|
77 |
for val in history:
|
@@ -82,19 +29,23 @@ Incorporate various fantasy subgenres:
|
|
82 |
messages.append({"role": "user", "content": message})
|
83 |
|
84 |
response = ""
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
-
|
95 |
-
|
|
|
|
|
|
|
96 |
|
97 |
-
|
|
|
98 |
respond,
|
99 |
additional_inputs=[
|
100 |
gr.Textbox(label="System Message", value="Write(output) in ํ๊ตญ์ด."),
|
@@ -103,21 +54,24 @@ demo = gr.ChatInterface(
|
|
103 |
gr.Slider(minimum=0, maximum=1, value=0.9, label="Top P"),
|
104 |
],
|
105 |
examples=[
|
106 |
-
|
107 |
-
|
108 |
-
|
109 |
-
|
110 |
-
|
111 |
-
|
112 |
-
|
113 |
-
|
114 |
],
|
115 |
title="Fantasy Novel AI Generation",
|
116 |
-
description="Fantasy Novel Generator: Create immersive fantasy worlds and epic adventures. Web(https://fantasy-novel-gen.hf.space)",
|
117 |
-
theme="Nymbo/Nymbo_Theme",
|
118 |
cache_examples=False,
|
119 |
-
|
120 |
)
|
121 |
|
|
|
122 |
if __name__ == "__main__":
|
123 |
-
|
|
|
|
|
|
|
|
|
|
6 |
import requests
|
7 |
|
8 |
# ์ถ๋ก API ํด๋ผ์ด์ธํธ ์ค์
|
9 |
+
hf_client = InferenceClient("CohereForAI/c4ai-command-r-plus-08-2024", token=os.getenv("HF_TOKEN"))
|
10 |
|
11 |
def respond(
|
12 |
message,
|
|
|
16 |
temperature=0.8,
|
17 |
top_p=0.9,
|
18 |
):
|
|
|
19 |
system_prefix = """
|
20 |
+
[์์คํ
ํ๋กฌํํธ ๋ด์ฉ...]
|
21 |
+
"""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
22 |
|
23 |
messages = [{"role": "system", "content": f"{system_prefix} {system_message}"}]
|
24 |
for val in history:
|
|
|
29 |
messages.append({"role": "user", "content": message})
|
30 |
|
31 |
response = ""
|
32 |
+
try:
|
33 |
+
for message in hf_client.chat_completion(
|
34 |
+
messages,
|
35 |
+
max_tokens=max_tokens,
|
36 |
+
stream=True,
|
37 |
+
temperature=temperature,
|
38 |
+
top_p=top_p,
|
39 |
+
):
|
40 |
+
token = message.choices[0].delta.content
|
41 |
+
if token is not None:
|
42 |
+
response += token.strip("")
|
43 |
+
yield response
|
44 |
+
except Exception as e:
|
45 |
+
yield f"Error: {str(e)}"
|
46 |
|
47 |
+
# Gradio ์ธํฐํ์ด์ค ์ค์
|
48 |
+
interface = gr.ChatInterface(
|
49 |
respond,
|
50 |
additional_inputs=[
|
51 |
gr.Textbox(label="System Message", value="Write(output) in ํ๊ตญ์ด."),
|
|
|
54 |
gr.Slider(minimum=0, maximum=1, value=0.9, label="Top P"),
|
55 |
],
|
56 |
examples=[
|
57 |
+
["ํํ์ง ์์ค์ ํฅ๋ฏธ๋ก์ด ์์ฌ 10๊ฐ์ง๋ฅผ ์ ์ํ๋ผ"],
|
58 |
+
["๊ณ์ ์ด์ด์ ์์ฑํ๋ผ"],
|
59 |
+
["Translate into English"],
|
60 |
+
["๋ง๋ฒ ์์คํ
์ ๋ํด ๋ ์์ธํ ์ค๋ช
ํ๋ผ"],
|
61 |
+
["์ ํฌ ์ฅ๋ฉด์ ๋ ๊ทน์ ์ผ๋ก ๋ฌ์ฌํ๋ผ"],
|
62 |
+
["์๋ก์ด ํํ์ง ์ข
์กฑ์ ์ถ๊ฐํ๋ผ"],
|
63 |
+
["๊ณ ๋ ์์ธ์ ๋ํด ๋ ์์ธํ ์ค๋ช
ํ๋ผ"],
|
64 |
+
["์ฃผ์ธ๊ณต์ ๋ด๋ฉด ๋ฌ์ฌ๋ฅผ ์ถ๊ฐํ๋ผ"],
|
65 |
],
|
66 |
title="Fantasy Novel AI Generation",
|
|
|
|
|
67 |
cache_examples=False,
|
68 |
+
theme="Yntec/HaleyCH_Theme_Orange"
|
69 |
)
|
70 |
|
71 |
+
# ์ ํ๋ฆฌ์ผ์ด์
์คํ
|
72 |
if __name__ == "__main__":
|
73 |
+
interface.launch(
|
74 |
+
server_name="0.0.0.0", # ๋ชจ๋ IP์์ ์ ๊ทผ ๊ฐ๋ฅ
|
75 |
+
server_port=7860, # ํฌํธ ์ง์
|
76 |
+
share=True # ๊ณต์ ๋งํฌ ์์ฑ
|
77 |
+
)
|