Spaces:
Running
Running
Commit
·
704d4a1
1
Parent(s):
82d7e57
Remove summary and mindmap fields from test function for cleaner data structure
Browse files
image.py
CHANGED
@@ -6,7 +6,7 @@ import requests
|
|
6 |
from urllib.parse import quote
|
7 |
from PIL import Image
|
8 |
from g4f.client import Client
|
9 |
-
from g4f.Provider import RetryProvider, PollinationsAI, Airforce
|
10 |
from g4f.Provider.hf_space.BlackForestLabsFlux1Schnell import BlackForestLabsFlux1Schnell
|
11 |
from g4f.Provider.hf_space.VoodoohopFlux1Schnell import VoodoohopFlux1Schnell
|
12 |
|
@@ -23,35 +23,88 @@ def fix_base64_padding(data):
|
|
23 |
data += "=" * (4 - missing_padding)
|
24 |
return data
|
25 |
|
26 |
-
def generate_image(title, category):
|
27 |
print("Generating image...")
|
28 |
import time
|
29 |
start = time.time()
|
30 |
try:
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
39 |
)
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
return
|
52 |
-
return None
|
53 |
except Exception as e:
|
54 |
-
print(f"
|
55 |
return None
|
56 |
|
57 |
def verify_image(image_data):
|
@@ -81,12 +134,13 @@ def upload_image(data_uri, api_key):
|
|
81 |
finally:
|
82 |
return image_url
|
83 |
|
84 |
-
def fetch_image(title, category, api_key):
|
85 |
title = r"{}".format(title)
|
86 |
category = r"{}".format(category)
|
|
|
87 |
image_url = "https://i.ibb.co/TBJqggw/Image-Not-Found.jpg"
|
88 |
try:
|
89 |
-
data_uri = generate_image(title, category)
|
90 |
if data_uri:
|
91 |
base64_image = fix_base64_padding(data_uri.split(",")[1])
|
92 |
image_data = None
|
@@ -109,8 +163,9 @@ def fetch_image(title, category, api_key):
|
|
109 |
|
110 |
|
111 |
if __name__ == "__main__":
|
112 |
-
title = "
|
113 |
-
category = "
|
|
|
114 |
api_key = "aa38b04047587c609f5c7e22f9d840f0"
|
115 |
-
image_url = fetch_image(title, category, api_key)
|
116 |
print(image_url)
|
|
|
6 |
from urllib.parse import quote
|
7 |
from PIL import Image
|
8 |
from g4f.client import Client
|
9 |
+
from g4f.Provider import RetryProvider, PollinationsAI, Airforce, ReplicateHome, BlackboxCreateAgent
|
10 |
from g4f.Provider.hf_space.BlackForestLabsFlux1Schnell import BlackForestLabsFlux1Schnell
|
11 |
from g4f.Provider.hf_space.VoodoohopFlux1Schnell import VoodoohopFlux1Schnell
|
12 |
|
|
|
23 |
data += "=" * (4 - missing_padding)
|
24 |
return data
|
25 |
|
26 |
+
def generate_image(title, category, summary):
|
27 |
print("Generating image...")
|
28 |
import time
|
29 |
start = time.time()
|
30 |
try:
|
31 |
+
try:
|
32 |
+
try:
|
33 |
+
negative="low quality, blurry, pixelated, bad anatomy, bad hands, three hands, three legs, bad arms, missing legs, missing arms, poorly drawn face, poorly rendered hands, bad face, fused face, cloned face, worst face, three crus, extra crus, fused crus, worst feet, three feet, fused feet, fused thigh, three thigh, extra thigh, worst thigh, missing fingers, extra fingers, ugly fingers, long fingers, bad composition, horn, extra eyes, huge eyes, 2girl, amputation, disconnected limbs, cartoon, cg, 3d, unreal, animate, cgi, render, artwork, illustration, 3d render, cinema 4d, artstation, octane render, mutated body parts, painting, oil painting, 2d, sketch, bad photography, bad photo, deviant art, aberrations, abstract, anime, black and white, collapsed, conjoined, creative, drawing, extra windows, harsh lighting, jpeg artifacts, low saturation, monochrome, multiple levels, overexposed, oversaturated, photoshop, rotten, surreal, twisted, UI, underexposed, unnatural, unreal engine, unrealistic, video game, deformed body features, NSFW, NUDE, vulgar, negative, unsuitable, inappropriate, offensive, revealing, sexual, explicit",
|
34 |
+
prompt = f"Generate accurate image representing the {category} concept: ```{title.strip()}: {summary.strip()}```"
|
35 |
+
print(prompt)
|
36 |
+
client = Client(
|
37 |
+
image_provider=RetryProvider(
|
38 |
+
providers=[ReplicateHome, Airforce],
|
39 |
+
shuffle=True,
|
40 |
+
single_provider_retry=True,
|
41 |
+
max_retries=3,
|
42 |
+
)
|
43 |
+
)
|
44 |
+
img_data = client.images.generate(
|
45 |
+
model="sdxl",
|
46 |
+
prompt=prompt,
|
47 |
+
negative_prompt=negative,
|
48 |
+
response_format="b64_json",
|
49 |
+
width=1024,
|
50 |
+
height=576,
|
51 |
+
).data[0].b64_json
|
52 |
+
print(f"Image generated in {time.time() - start:.2f} seconds")
|
53 |
+
if img_data:
|
54 |
+
return f"data:image/png;base64,{img_data}"
|
55 |
+
return None
|
56 |
+
except Exception as e:
|
57 |
+
print(f"Error generating image: {e}")
|
58 |
+
negative="low quality, blurry, pixelated, bad anatomy, bad hands, three hands, three legs, bad arms, missing legs, missing arms, poorly drawn face, poorly rendered hands, bad face, fused face, cloned face, worst face, three crus, extra crus, fused crus, worst feet, three feet, fused feet, fused thigh, three thigh, extra thigh, worst thigh, missing fingers, extra fingers, ugly fingers, long fingers, bad composition, horn, extra eyes, huge eyes, 2girl, amputation, disconnected limbs, cartoon, cg, 3d, unreal, animate, cgi, render, artwork, illustration, 3d render, cinema 4d, artstation, octane render, mutated body parts, painting, oil painting, 2d, sketch, bad photography, bad photo, deviant art, aberrations, abstract, anime, black and white, collapsed, conjoined, creative, drawing, extra windows, harsh lighting, jpeg artifacts, low saturation, monochrome, multiple levels, overexposed, oversaturated, photoshop, rotten, surreal, twisted, UI, underexposed, unnatural, unreal engine, unrealistic, video game, deformed body features, NSFW, NUDE, vulgar, negative, unsuitable, inappropriate, offensive, revealing, sexual, explicit",
|
59 |
+
prompt = f"Generate accurate image representing the {category} concept: ```{title.strip()}: {summary.strip()}```"
|
60 |
+
print(prompt)
|
61 |
+
client = Client(
|
62 |
+
image_provider=RetryProvider(
|
63 |
+
providers=[Airforce, PollinationsAI, BlackboxCreateAgent],
|
64 |
+
shuffle=True,
|
65 |
+
single_provider_retry=True,
|
66 |
+
max_retries=3,
|
67 |
+
)
|
68 |
+
)
|
69 |
+
img_data = client.images.generate(
|
70 |
+
model="flux",
|
71 |
+
prompt=prompt,
|
72 |
+
negative_prompt=negative,
|
73 |
+
response_format="b64_json",
|
74 |
+
width=1024,
|
75 |
+
height=576,
|
76 |
+
).data[0].b64_json
|
77 |
+
print(f"Image generated in {time.time() - start:.2f} seconds")
|
78 |
+
if img_data:
|
79 |
+
return f"data:image/png;base64,{img_data}"
|
80 |
+
return None
|
81 |
+
except Exception as e:
|
82 |
+
print(f"Error generating image: {e}")
|
83 |
+
negative="low quality, blurry, pixelated, bad anatomy, bad hands, three hands, three legs, bad arms, missing legs, missing arms, poorly drawn face, poorly rendered hands, bad face, fused face, cloned face, worst face, three crus, extra crus, fused crus, worst feet, three feet, fused feet, fused thigh, three thigh, extra thigh, worst thigh, missing fingers, extra fingers, ugly fingers, long fingers, bad composition, horn, extra eyes, huge eyes, 2girl, amputation, disconnected limbs, cartoon, cg, 3d, unreal, animate, cgi, render, artwork, illustration, 3d render, cinema 4d, artstation, octane render, mutated body parts, painting, oil painting, 2d, sketch, bad photography, bad photo, deviant art, aberrations, abstract, anime, black and white, collapsed, conjoined, creative, drawing, extra windows, harsh lighting, jpeg artifacts, low saturation, monochrome, multiple levels, overexposed, oversaturated, photoshop, rotten, surreal, twisted, UI, underexposed, unnatural, unreal engine, unrealistic, video game, deformed body features, NSFW, NUDE, vulgar, negative, unsuitable, inappropriate, offensive, revealing, sexual, explicit",
|
84 |
+
prompt = f"Generate accurate image representing the {category} concept: ```{title.strip()}: {summary.strip()}```"
|
85 |
+
print(prompt)
|
86 |
+
client = Client(
|
87 |
+
image_provider=RetryProvider(
|
88 |
+
providers=[BlackForestLabsFlux1Schnell, VoodoohopFlux1Schnell],
|
89 |
+
shuffle=True,
|
90 |
+
single_provider_retry=True,
|
91 |
+
max_retries=3,
|
92 |
+
)
|
93 |
)
|
94 |
+
img_data = client.images.generate(
|
95 |
+
model="flux-schnell",
|
96 |
+
prompt=prompt,
|
97 |
+
negative_prompt=negative,
|
98 |
+
response_format="b64_json",
|
99 |
+
width=1024,
|
100 |
+
height=576,
|
101 |
+
).data[0].b64_json
|
102 |
+
print(f"Image generated in {time.time() - start:.2f} seconds")
|
103 |
+
if img_data:
|
104 |
+
return f"data:image/png;base64,{img_data}"
|
105 |
+
return None
|
|
|
106 |
except Exception as e:
|
107 |
+
print(f"Error generating image: {e}")
|
108 |
return None
|
109 |
|
110 |
def verify_image(image_data):
|
|
|
134 |
finally:
|
135 |
return image_url
|
136 |
|
137 |
+
def fetch_image(title, category, summary, api_key):
|
138 |
title = r"{}".format(title)
|
139 |
category = r"{}".format(category)
|
140 |
+
summary = extract_summary(summary)
|
141 |
image_url = "https://i.ibb.co/TBJqggw/Image-Not-Found.jpg"
|
142 |
try:
|
143 |
+
data_uri = generate_image(title, category, summary)
|
144 |
if data_uri:
|
145 |
base64_image = fix_base64_padding(data_uri.split(",")[1])
|
146 |
image_data = None
|
|
|
163 |
|
164 |
|
165 |
if __name__ == "__main__":
|
166 |
+
title = "Exposition: Enumerative Geometry and Tree-Level Gromov-Witten Invariants"
|
167 |
+
category = "Mathematics"
|
168 |
+
summary = "The text discusses the Kontsevich-Manin formula for enumerating degree d rational curves via Gromov-Witten invariants. It details the calculation of these invariants using moduli spaces of stable maps and explores their implications in enumerative geometry."
|
169 |
api_key = "aa38b04047587c609f5c7e22f9d840f0"
|
170 |
+
image_url = fetch_image(title, category, summary, api_key)
|
171 |
print(image_url)
|
main.py
CHANGED
@@ -83,8 +83,6 @@ def test(uaccess_key):
|
|
83 |
"category":"Economics",
|
84 |
"pdf_url":"https://arxiv.org/pdf/2501.00578",
|
85 |
"citation":"Miller, A. D. (2025). The limits of tolerance (Version 1). arXiv. https://doi.org/10.48550/ARXIV.2501.00578",
|
86 |
-
"summary":"## Summary\nThe text discusses the concept of community standards in relation to good faith terminations and the criminalization of obscene speech in the U.S. It introduces a model for aggregating community judgments represented as intervals, focusing on endpoint rules that can ensure strategyproofness and responsiveness in preference aggregation.\n\n## Highlights\n- Community standards are referenced for good faith terminations.\n- Obscene speech can be criminalized based on contemporary community standards.\n- A model is introduced where judgments are represented as intervals on the real line.\n- The p,q-th endpoint rule aggregates these judgments.\n- Endpoint rules allow for independent aggregation of upper and lower endpoints.\n- Generalized single-peaked preferences are defined for effective aggregation.\n- The maximal rule represents the most liberal approach to community standards.\n\n## Key Insights\n- Community Standards and Good Faith: The reliance on community standards for terminations reflects societal values, which can fluctuate over time, necessitating a flexible approach to legal interpretations.\n- Obscenity and Free Speech: The ability to criminalize obscene speech underlines the tension between individual rights and community morals, highlighting the complexities in defining obscenity.\n- Interval Representation: The model of representing judgments as intervals allows for a more nuanced understanding of community preferences, accommodating diverse opinions while still aiming for consensus.\n- Endpoint Rules: These rules facilitate a structured method for aggregating individual judgments, ensuring that preferences are considered without diminishing the integrity of the decision-making process.\n- Generalized Single-Peaked Preferences: This concept aids in simplifying the aggregation of preferences by establishing a clear peak, which enhances the efficiency of collective decision-making.\n- Strategyproofness in Voting: By ensuring that preferences are aggregated independently, the model maintains fairness and prevents manipulation, reinforcing the integrity of democratic processes.\n- Liberalism vs. Democracy: The discussion draws a connection between endpoint rules and broader political philosophies, suggesting that the balance between individual freedoms and collective decision-making is crucial for effective governance.",
|
87 |
-
"mindmap":"## Terminations of Good Faith\n- Reference to community standards of decency\n- Fairness and reasonableness in terminations\n\n## Obscenity and Free Speech\n- Criminalization based on contemporary community standards\n- Free speech protections may not apply\n\n## Community Standards Model\n- Standards represented by real line intervals\n- Judgment takes the form of intervals\n\n## Endpoint Rules\n- Defined by p-th lowest and q-th highest\n- Aggregate judgments based on endpoints\n\n## Strategyproofness Implications\n- Restrict allowable preferences for strategyproofness\n- Single-peaked preferences enable non-dictatorial rules\n\n## Generalized Single-Peaked Preferences\n- Unique preferred interval called the \"peak\"\n- Intervals between peak and third are preferred\n\n## Aggregation of Endpoints\n- Independent aggregation of upper and lower endpoints\n- Characterized by responsiveness and neutrality axioms\n\n## Median and Maximal Rules\n- Median rule is least permissive, satisfies conditions\n- Maximal rule allows any reasonable action\n\n## Phantom Intervals\n- Include half-bounded and fully unbounded intervals\n- Used in interval aggregation models\n\n## Axioms in Aggregation Methods\n- Seven axioms define endpoint rule characteristics\n- Ensures fair aggregation of individual judgments"
|
88 |
},
|
89 |
},
|
90 |
}
|
|
|
83 |
"category":"Economics",
|
84 |
"pdf_url":"https://arxiv.org/pdf/2501.00578",
|
85 |
"citation":"Miller, A. D. (2025). The limits of tolerance (Version 1). arXiv. https://doi.org/10.48550/ARXIV.2501.00578",
|
|
|
|
|
86 |
},
|
87 |
},
|
88 |
}
|