Upload app-fanta-backup.py
Browse files- app-fanta-backup.py +123 -0
app-fanta-backup.py
ADDED
@@ -0,0 +1,123 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# -*- coding: utf-8 -*-
|
2 |
+
|
3 |
+
import gradio as gr
|
4 |
+
from huggingface_hub import InferenceClient
|
5 |
+
import os
|
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,
|
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 |
+
Guidelines for fantasy novel generation:
|
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:
|
78 |
+
if val[0]:
|
79 |
+
messages.append({"role": "user", "content": val[0]})
|
80 |
+
if val[1]:
|
81 |
+
messages.append({"role": "assistant", "content": val[1]})
|
82 |
+
messages.append({"role": "user", "content": message})
|
83 |
+
|
84 |
+
response = ""
|
85 |
+
for message in hf_client.chat_completion(
|
86 |
+
messages,
|
87 |
+
max_tokens=max_tokens,
|
88 |
+
stream=True,
|
89 |
+
temperature=temperature,
|
90 |
+
top_p=top_p,
|
91 |
+
):
|
92 |
+
token = message.choices[0].delta.content
|
93 |
+
if token is not None:
|
94 |
+
response += token.strip("")
|
95 |
+
yield response
|
96 |
+
|
97 |
+
demo = gr.ChatInterface(
|
98 |
+
respond,
|
99 |
+
additional_inputs=[
|
100 |
+
gr.Textbox(label="System Message", value="Write(output) in νκ΅μ΄."),
|
101 |
+
gr.Slider(minimum=1, maximum=8000, value=7000, label="Max Tokens"),
|
102 |
+
gr.Slider(minimum=0, maximum=1, value=0.7, label="Temperature"),
|
103 |
+
gr.Slider(minimum=0, maximum=1, value=0.9, label="Top P"),
|
104 |
+
],
|
105 |
+
examples=[
|
106 |
+
["ννμ§ μμ€μ ν₯λ―Έλ‘μ΄ μμ¬ 10κ°μ§λ₯Ό μ μνλΌ"],
|
107 |
+
["κ³μ μ΄μ΄μ μμ±νλΌ"],
|
108 |
+
["Translate into English"],
|
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 |
+
css="""footer {visibility: hidden}"""
|
120 |
+
)
|
121 |
+
|
122 |
+
if __name__ == "__main__":
|
123 |
+
demo.launch(auth=("gini","pick"))
|