fantaxy commited on
Commit
c83463b
ยท
verified ยท
1 Parent(s): 03ceb55

Update app-fanta-backup.py

Browse files
Files changed (1) hide show
  1. 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= os.getenv("HF_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
- 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:
@@ -82,19 +29,23 @@ Incorporate various fantasy subgenres:
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 ํ•œ๊ตญ์–ด."),
@@ -103,21 +54,24 @@ demo = gr.ChatInterface(
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"))
 
 
 
 
 
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
+ )