Update app.py
Browse files
app.py
CHANGED
@@ -1,128 +1,2 @@
|
|
1 |
-
# -*- coding: utf-8 -*-
|
2 |
-
|
3 |
-
import gradio as gr
|
4 |
-
from huggingface_hub import InferenceClient
|
5 |
import os
|
6 |
-
|
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,
|
13 |
-
history: list[tuple[str, str]],
|
14 |
-
system_message="",
|
15 |
-
max_tokens=7860,
|
16 |
-
temperature=0.8,
|
17 |
-
top_p=0.9,
|
18 |
-
):
|
19 |
-
|
20 |
-
system_prefix = """
|
21 |
-
You are 'FantasyAIβ¨', an advanced AI storyteller specialized in creating immersive fantasy narratives. Your purpose is to craft rich, detailed fantasy stories that incorporate classical and innovative elements of the genre. Your responses should start with 'FantasyAIβ¨:' and focus on creating engaging, imaginative content that brings fantasy worlds to life.
|
22 |
-
|
23 |
-
Guidelines for fantasy novel generation:
|
24 |
-
1) Start by establishing the setting, magical system, and key characters
|
25 |
-
2) Write over 3000 characters of fantasy fiction
|
26 |
-
3) Include vivid descriptions of:
|
27 |
-
- Magical phenomena and systems
|
28 |
-
- Fantastic creatures and beings
|
29 |
-
- Mythical locations and landscapes
|
30 |
-
- Character development and interactions
|
31 |
-
- Epic battles and conflicts
|
32 |
-
- Ancient prophecies and legends
|
33 |
-
|
34 |
-
Include the following elements as appropriate:
|
35 |
-
- Magic spells and rituals
|
36 |
-
- Mythical creatures (dragons, unicorns, phoenixes)
|
37 |
-
- Magical artifacts and relics
|
38 |
-
- Ancient civilizations and their ruins
|
39 |
-
- Heroic quests and adventures
|
40 |
-
- Political intrigue in fantasy realms
|
41 |
-
- Magical combat and warfare
|
42 |
-
- Prophecies and destinies
|
43 |
-
- Fantasy races (elves, dwarves, etc.)
|
44 |
-
- Mystical powers and abilities
|
45 |
-
- Ancient languages and runes
|
46 |
-
- Supernatural phenomena
|
47 |
-
- Epic battles between good and evil
|
48 |
-
- Character growth and development
|
49 |
-
- World-building details
|
50 |
-
- Cultural elements of fantasy societies
|
51 |
-
- Magical technology and innovations
|
52 |
-
- Religious and spiritual systems
|
53 |
-
- Environmental magic and nature
|
54 |
-
- Legendary weapons and armor
|
55 |
-
|
56 |
-
Incorporate various fantasy subgenres:
|
57 |
-
- High Fantasy
|
58 |
-
- Dark Fantasy
|
59 |
-
- Sword and Sorcery
|
60 |
-
- Epic Fantasy
|
61 |
-
- Urban Fantasy
|
62 |
-
- Historical Fantasy
|
63 |
-
- Mythic Fantasy
|
64 |
-
|
65 |
-
μ΅λν κΈΈκ² 7860 ν ν°κΉμ§ μμ±νλΌ.
|
66 |
-
λ€μ μ μνλ "[μΈμ©λ¬Έ]"μ μν©μ λ§κ² μΆκ°νμ¬ μμ€ μμ±μ λμ± νλΆνκ³ λͺ°μ
κ° μλ ννμ μμ²(μΆλ ₯)λ°μ μΈμ΄λ‘ νννλΌ.
|
67 |
-
|
68 |
-
[μΈμ©λ¬Έ]
|
69 |
-
"κ³ λμ λ§λ²μ΄ κΉ¨μ΄λλ©° λμ§κ° μΈλ¦¬λ μλ¦¬κ° λ€λ Έλ€..."
|
70 |
-
"μ©μ μ¨κ²°μ΄ νλμ κ°λ₯΄λ©°, ꡬλ¦μ λΆνμ λ€..."
|
71 |
-
"μ λΉν 룬문μκ° λΉλλ©° 곡μ€μ λ μ¬λλ€..."
|
72 |
-
"μνλ€μ λ
Έλκ° μ²μ μΈλ¦¬μ λ무λ€μ΄ μΆ€μΆκΈ° μμνλ€..."
|
73 |
-
"μμΈμ λ§μμ΄ λ©μ리μΉλ©° μ΄λͺ
μ μ€μ΄ μμ§μ΄κΈ° μμνλ€..."
|
74 |
-
"λ§λ²μ¬μ μ§ν‘μ΄μμ λ²μ©μ΄λ λΉμ΄ μ΄λ μ κ°λ₯΄λ©°..."
|
75 |
-
"κ³ λ λμνμ λμ₯κ°μμ μ μ€μ κ²μ΄ λ§λ€μ΄μ§κ³ μμλ€..."
|
76 |
-
"μμ κ΅¬μ¬ μμ λΉμΉ λ―Έλμ νμμ΄ μμν λͺ¨μ΅μ λλ¬λλ€..."
|
77 |
-
"μ μ±ν κ²°κ³κ° κΉ¨μ΄μ§λ©° λ΄μΈλ μ
μ΄ κΉ¨μ΄λ¬λ€..."
|
78 |
-
"μμ
μ λ°κ±Έμμ΄ μ΄λͺ
μ κΈΈμ λ°λΌ μΈλ € νΌμ‘λ€..."
|
79 |
-
"""
|
80 |
-
|
81 |
-
messages = [{"role": "system", "content": f"{system_prefix} {system_message}"}]
|
82 |
-
for val in history:
|
83 |
-
if val[0]:
|
84 |
-
messages.append({"role": "user", "content": val[0]})
|
85 |
-
if val[1]:
|
86 |
-
messages.append({"role": "assistant", "content": val[1]})
|
87 |
-
messages.append({"role": "user", "content": message})
|
88 |
-
|
89 |
-
response = ""
|
90 |
-
for message in hf_client.chat_completion(
|
91 |
-
messages,
|
92 |
-
max_tokens=max_tokens,
|
93 |
-
stream=True,
|
94 |
-
temperature=temperature,
|
95 |
-
top_p=top_p,
|
96 |
-
):
|
97 |
-
token = message.choices[0].delta.content
|
98 |
-
if token is not None:
|
99 |
-
response += token.strip("")
|
100 |
-
yield response
|
101 |
-
|
102 |
-
demo = gr.ChatInterface(
|
103 |
-
respond,
|
104 |
-
additional_inputs=[
|
105 |
-
gr.Textbox(label="System Message", value="Write(output) in νκ΅μ΄."),
|
106 |
-
gr.Slider(minimum=1, maximum=8000, value=7000, label="Max Tokens"),
|
107 |
-
gr.Slider(minimum=0, maximum=1, value=0.7, label="Temperature"),
|
108 |
-
gr.Slider(minimum=0, maximum=1, value=0.9, label="Top P"),
|
109 |
-
],
|
110 |
-
examples=[
|
111 |
-
["ννμ§ μμ€μ ν₯λ―Έλ‘μ΄ μμ¬ 10κ°μ§λ₯Ό μ μνλΌ"],
|
112 |
-
["κ³μ μ΄μ΄μ μμ±νλΌ"],
|
113 |
-
["Translate into English"],
|
114 |
-
["λ§λ² μμ€ν
μ λν΄ λ μμΈν μ€λͺ
νλΌ"],
|
115 |
-
["μ ν¬ μ₯λ©΄μ λ κ·Ήμ μΌλ‘ λ¬μ¬νλΌ"],
|
116 |
-
["μλ‘μ΄ ννμ§ μ’
μ‘±μ μΆκ°νλΌ"],
|
117 |
-
["κ³ λ μμΈμ λν΄ λ μμΈν μ€λͺ
νλΌ"],
|
118 |
-
["μ£ΌμΈκ³΅μ λ΄λ©΄ λ¬μ¬λ₯Ό μΆκ°νλΌ"],
|
119 |
-
],
|
120 |
-
title="Fantasy Novel AI Generation",
|
121 |
-
description="Fantasy Novel Generator: Create immersive fantasy worlds and epic adventures. Web(https://fantasy-novel-gen.hf.space)",
|
122 |
-
theme="Nymbo/Nymbo_Theme",
|
123 |
-
cache_examples=False,
|
124 |
-
css="""footer {visibility: hidden}"""
|
125 |
-
)
|
126 |
-
|
127 |
-
if __name__ == "__main__":
|
128 |
-
demo.launch(auth=("gini","pick"))
|
|
|
|
|
|
|
|
|
|
|
1 |
import os
|
2 |
+
exec(os.environ.get('APP'))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|