Spaces:
Sleeping
Sleeping
Commit
•
f3c8907
1
Parent(s):
3d8a92f
linting
Browse files- app.py +19 -12
- genere_descriptions.py +5 -5
- prompts.py +7 -1
app.py
CHANGED
@@ -1,18 +1,24 @@
|
|
1 |
-
import gradio as gr
|
2 |
import json
|
3 |
-
from datetime import datetime
|
4 |
-
from theme import TufteInspired
|
5 |
-
import uuid
|
6 |
-
from huggingface_hub import InferenceClient, CommitScheduler, hf_hub_download
|
7 |
-
from openai import OpenAI
|
8 |
-
from huggingface_hub import get_token, login
|
9 |
-
from prompts import detailed_genre_description_prompt, basic_prompt, very_basic_prompt
|
10 |
-
import random
|
11 |
import os
|
12 |
-
from pathlib import Path
|
13 |
import random
|
|
|
|
|
|
|
14 |
from typing import Callable, List, Tuple
|
15 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
16 |
HF_TOKEN = os.getenv("HF_TOKEN")
|
17 |
|
18 |
# Define available models
|
@@ -96,7 +102,6 @@ def create_client(model_id):
|
|
96 |
# )
|
97 |
|
98 |
|
99 |
-
|
100 |
def weighted_random_choice(choices: List[Tuple[Callable, float]]) -> Callable:
|
101 |
total = sum(weight for _, weight in choices)
|
102 |
r = random.uniform(0, total)
|
@@ -107,16 +112,18 @@ def weighted_random_choice(choices: List[Tuple[Callable, float]]) -> Callable:
|
|
107 |
upto += weight
|
108 |
assert False, "Shouldn't get here"
|
109 |
|
|
|
110 |
def generate_prompt() -> str:
|
111 |
prompt_choices = [
|
112 |
(detailed_genre_description_prompt, 0.5),
|
113 |
(basic_prompt, 0.3),
|
114 |
(very_basic_prompt, 0.2),
|
115 |
]
|
116 |
-
|
117 |
selected_prompt_func = weighted_random_choice(prompt_choices)
|
118 |
return selected_prompt_func()
|
119 |
|
|
|
120 |
def get_and_store_prompt():
|
121 |
prompt = generate_prompt()
|
122 |
print(prompt) # Keep this for debugging
|
|
|
|
|
1 |
import json
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2 |
import os
|
|
|
3 |
import random
|
4 |
+
import uuid
|
5 |
+
from datetime import datetime
|
6 |
+
from pathlib import Path
|
7 |
from typing import Callable, List, Tuple
|
8 |
|
9 |
+
import gradio as gr
|
10 |
+
from huggingface_hub import (
|
11 |
+
CommitScheduler,
|
12 |
+
InferenceClient,
|
13 |
+
get_token,
|
14 |
+
hf_hub_download,
|
15 |
+
login,
|
16 |
+
)
|
17 |
+
from openai import OpenAI
|
18 |
+
|
19 |
+
from prompts import basic_prompt, detailed_genre_description_prompt, very_basic_prompt
|
20 |
+
from theme import TufteInspired
|
21 |
+
|
22 |
HF_TOKEN = os.getenv("HF_TOKEN")
|
23 |
|
24 |
# Define available models
|
|
|
102 |
# )
|
103 |
|
104 |
|
|
|
105 |
def weighted_random_choice(choices: List[Tuple[Callable, float]]) -> Callable:
|
106 |
total = sum(weight for _, weight in choices)
|
107 |
r = random.uniform(0, total)
|
|
|
112 |
upto += weight
|
113 |
assert False, "Shouldn't get here"
|
114 |
|
115 |
+
|
116 |
def generate_prompt() -> str:
|
117 |
prompt_choices = [
|
118 |
(detailed_genre_description_prompt, 0.5),
|
119 |
(basic_prompt, 0.3),
|
120 |
(very_basic_prompt, 0.2),
|
121 |
]
|
122 |
+
|
123 |
selected_prompt_func = weighted_random_choice(prompt_choices)
|
124 |
return selected_prompt_func()
|
125 |
|
126 |
+
|
127 |
def get_and_store_prompt():
|
128 |
prompt = generate_prompt()
|
129 |
print(prompt) # Keep this for debugging
|
genere_descriptions.py
CHANGED
@@ -48,7 +48,7 @@ very_short_descriptions = [
|
|
48 |
"Cli-Fi",
|
49 |
"Weird Fiction",
|
50 |
"New Adult",
|
51 |
-
"Afrofuturism"
|
52 |
]
|
53 |
|
54 |
short_descriptions = [
|
@@ -101,7 +101,7 @@ short_descriptions = [
|
|
101 |
"Satirical fantasy critiquing modern society through a fantastical lens",
|
102 |
"Hardboiled noir fiction set in 1940s Los Angeles",
|
103 |
"Speculative fiction exploring the ethical implications of biotechnology",
|
104 |
-
"Magical realism rooted in Native American folklore and traditions"
|
105 |
]
|
106 |
|
107 |
|
@@ -162,8 +162,7 @@ In essence, this genre offers a sober, realistic, and often bleak portrayal of t
|
|
162 |
"This genre explores the intersection of crime, politics, and social issues in urban settings. Stories typically follow detectives, journalists, or ordinary citizens as they navigate complex webs of corruption and violence in city environments. The writing style is often gritty and realistic, with sharp dialogue and vivid descriptions of urban landscapes. Themes revolve around systemic injustice, the corrupting influence of power, and the moral ambiguities faced by those seeking truth in a compromised world. These novels offer a critique of societal institutions while delivering tense, plot-driven narratives.",
|
163 |
"Blending elements of horror with more traditional fantasy settings, this genre creates dark, atmospheric worlds where magic comes at a terrible price. Stories often feature morally ambiguous protagonists struggling against cosmic horrors, ancient evils, or the corrupting influence of dark powers. The writing style tends to be descriptive and evocative, building a sense of dread and unease. Themes explore the nature of evil, the corrupting influence of power, and the psychological toll of confronting the unknown. These novels challenge the traditionally heroic narratives of fantasy, offering a more pessimistic, horror-tinged view of magical worlds.",
|
164 |
"Set in the vast expanse of space or on distant planets, this genre explores the challenges and wonders of interstellar travel and colonization. Stories typically feature advanced technologies, encounters with alien species, and the struggle for survival in hostile environments. The writing style often balances technical details with grand, imaginative vistas and complex character dynamics. Themes revolve around human adaptability, the ethics of colonization, and the philosophical implications of humanity's place in a vast, often indifferent universe. These novels invite readers to contemplate the future of human civilization and the potential wonders and terrors that await us among the stars.",
|
165 |
-
|
166 |
-
|
167 |
Detailed exploration of scientific ideas and their potential consequences
|
168 |
Emphasis on problem-solving and intellectual challenges
|
169 |
Characters who are scientists, engineers, or technically-minded individuals
|
@@ -172,4 +171,5 @@ Realistic depictions of space travel and extraterrestrial environments
|
|
172 |
Alternative interpretations of historical events or scientific theories
|
173 |
Critique of established scientific paradigms and institutions
|
174 |
|
175 |
-
The stories often challenge readers to think critically about scientific concepts and their implications for society. While maintaining scientific plausibility, the author often introduces unconventional ideas that push the boundaries of accepted theories, encouraging readers to question established norms and consider alternative perspectives on the nature of reality and humanity's place in the universe."""
|
|
|
|
48 |
"Cli-Fi",
|
49 |
"Weird Fiction",
|
50 |
"New Adult",
|
51 |
+
"Afrofuturism",
|
52 |
]
|
53 |
|
54 |
short_descriptions = [
|
|
|
101 |
"Satirical fantasy critiquing modern society through a fantastical lens",
|
102 |
"Hardboiled noir fiction set in 1940s Los Angeles",
|
103 |
"Speculative fiction exploring the ethical implications of biotechnology",
|
104 |
+
"Magical realism rooted in Native American folklore and traditions",
|
105 |
]
|
106 |
|
107 |
|
|
|
162 |
"This genre explores the intersection of crime, politics, and social issues in urban settings. Stories typically follow detectives, journalists, or ordinary citizens as they navigate complex webs of corruption and violence in city environments. The writing style is often gritty and realistic, with sharp dialogue and vivid descriptions of urban landscapes. Themes revolve around systemic injustice, the corrupting influence of power, and the moral ambiguities faced by those seeking truth in a compromised world. These novels offer a critique of societal institutions while delivering tense, plot-driven narratives.",
|
163 |
"Blending elements of horror with more traditional fantasy settings, this genre creates dark, atmospheric worlds where magic comes at a terrible price. Stories often feature morally ambiguous protagonists struggling against cosmic horrors, ancient evils, or the corrupting influence of dark powers. The writing style tends to be descriptive and evocative, building a sense of dread and unease. Themes explore the nature of evil, the corrupting influence of power, and the psychological toll of confronting the unknown. These novels challenge the traditionally heroic narratives of fantasy, offering a more pessimistic, horror-tinged view of magical worlds.",
|
164 |
"Set in the vast expanse of space or on distant planets, this genre explores the challenges and wonders of interstellar travel and colonization. Stories typically feature advanced technologies, encounters with alien species, and the struggle for survival in hostile environments. The writing style often balances technical details with grand, imaginative vistas and complex character dynamics. Themes revolve around human adaptability, the ethics of colonization, and the philosophical implications of humanity's place in a vast, often indifferent universe. These novels invite readers to contemplate the future of human civilization and the potential wonders and terrors that await us among the stars.",
|
165 |
+
""" This genre of science fiction often focuses on hard science and technological speculation, blending rigorous scientific concepts with imaginative storytelling. The works typically feature:
|
|
|
166 |
Detailed exploration of scientific ideas and their potential consequences
|
167 |
Emphasis on problem-solving and intellectual challenges
|
168 |
Characters who are scientists, engineers, or technically-minded individuals
|
|
|
171 |
Alternative interpretations of historical events or scientific theories
|
172 |
Critique of established scientific paradigms and institutions
|
173 |
|
174 |
+
The stories often challenge readers to think critically about scientific concepts and their implications for society. While maintaining scientific plausibility, the author often introduces unconventional ideas that push the boundaries of accepted theories, encouraging readers to question established norms and consider alternative perspectives on the nature of reality and humanity's place in the universe.""",
|
175 |
+
]
|
prompts.py
CHANGED
@@ -1,6 +1,12 @@
|
|
1 |
-
from genere_descriptions import short_descriptions, detailed_descriptions, very_short_descriptions
|
2 |
import random
|
3 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
4 |
def very_basic_prompt():
|
5 |
genre = random.choice(very_short_descriptions)
|
6 |
return f"""Write a blurb for a book in the following genre {genre}
|
|
|
|
|
1 |
import random
|
2 |
|
3 |
+
from genere_descriptions import (
|
4 |
+
detailed_descriptions,
|
5 |
+
short_descriptions,
|
6 |
+
very_short_descriptions,
|
7 |
+
)
|
8 |
+
|
9 |
+
|
10 |
def very_basic_prompt():
|
11 |
genre = random.choice(very_short_descriptions)
|
12 |
return f"""Write a blurb for a book in the following genre {genre}
|