Skip to content

Commit

Permalink
update with new components
Browse files Browse the repository at this point in the history
  • Loading branch information
leeduckgo committed Dec 13, 2023
1 parent 9eeca78 commit e5b606e
Show file tree
Hide file tree
Showing 18 changed files with 186 additions and 15 deletions.
35 changes: 35 additions & 0 deletions galxe_graphql_collection/campaign_list.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
{
"alias": "bnbchain",
"campaignInput": {
"forAdmin": false,
"first": 2,
"after": "-1",
"excludeChildren": true,
"gasTypes": null,
"credSources": null,
"rewardTypes": null,
"chains": null,
"statuses": null,
"listType": "Newest",
"types": [
"Drop",
"MysteryBox",
"Forge",
"MysteryBoxWR",
"Airdrop",
"ExternalLink",
"OptIn",
"OptInEmail",
"PowahDrop",
"Parent",
"Oat",
"Bounty",
"Token",
"DiscordRole",
"Mintlist",
"Points",
"PointsMysteryBox"
],
"searchString": null
}
}
21 changes: 21 additions & 0 deletions galxe_graphql_collection/campaign_list.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
query CampaignList(
$id: Int
$alias: String
$campaignInput: ListCampaignInput!
) {
space(id: $id, alias: $alias) {
id
name
alias
campaigns(input: $campaignInput) {
pageInfo {
endCursor
hasNextPage
}
list {
id
name
}
}
}
}
73 changes: 64 additions & 9 deletions lib/components/ai_pic.ex
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
defmodule Components.AiPic do

use HTTPoison.Base
alias Tesla.Multipart

@base "https://clipdrop-api.co"
def text_to_image(prompt) do
client = client()
file_name = do_text_to_image(client, prompt)
file_name
end

def client() do
Tesla.client([
Expand All @@ -16,16 +12,75 @@ defmodule Components.AiPic do
])
end

# +-------------+
# | text to img |
# +-------------+

def text_to_image(prompt) do
client = client()
file_name = do_text_to_image(client, prompt)
"images/#{file_name}.png"
end

def do_text_to_image(client, prompt) do
mp = Multipart.new()
|> Multipart.add_content_type_param("charset=utf-8")
|> Multipart.add_field("prompt", prompt,
headers: [{"content-type", "text/plain"}]
)
{:ok, %{body: img_raw}} =
Tesla.post(client, "/text-to-image/v1", mp)
file_name = RandGen.gen_hex(10)
File.write("priv/static/images/#{file_name}.png", img_raw)
file_name
end

# +---------------+
# | sketch to img |
# +---------------+
# TODO: some type of pics are not working, waiting the guys to fix it.
def sketch_to_image(file_url, prompt) do
client = client()
file_name = do_sketch_to_image(client, file_url, prompt)
"images/#{file_name}.png"
end

def do_sketch_to_image(client, file_url, prompt) do
# TODO: download the file to the local.
mp = Tesla.Multipart.new()
|> Tesla.Multipart.add_content_type_param("charset=utf-8")
|> Tesla.Multipart.add_field("prompt", prompt,
headers: [{"content-type", "text/plain"}]
)
|> Multipart.add_file(
"priv/static/images/sketch_example.png", name: "sketch_file") # TODO: update here.
{:ok, %{body: img_raw}} =
Tesla.post(client, "/text-to-image/v1", mp)
Tesla.post(client, "/sketch-to-image/v1/sketch-to-image/", mp)
file_name = RandGen.gen_hex(10)
File.write("priv/static/images/#{file_name}.png", img_raw)
file_name
end

# +-------------------+
# | reimagine the img |
# +-------------------+

def reimagine(file_url) do
client = client()
file_name = do_reimagine(client, file_url)
"images/#{file_name}.png"
end

def do_reimagine(client, file_url) do
mp = Tesla.Multipart.new()
|> Multipart.add_file(
"priv/static/images/sketch_example.png", # TODO: update here.
name: "image_file"
)

{:ok, %{body: img_raw}} =
Tesla.post(client, "/reimagine/v1/reimagine/", mp)
file_name = RandGen.gen_hex(10)
File.write("pic_generated/#{file_name}.png", img_raw)
File.write("priv/static/images/#{file_name}.png", img_raw)
file_name
end

Expand Down
59 changes: 59 additions & 0 deletions lib/components/galxe_graphql_interactor.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
defmodule Components.GalxeGraphQLInteractor do

@url "https://graphigo.prd.galaxy.eco/query"
alias Neuron.Config

def query_campaign_list(the_alias, fir, aft) do
Config.set(url: @url)
body = "query CampaignList(\n $id: Int\n $alias: String\n $campaignInput: ListCampaignInput!\n) {\n space(id: $id, alias: $alias) {\n id\n name\n alias\n campaigns(input: $campaignInput) {\n pageInfo {\n endCursor\n hasNextPage\n }\n list {\n id\n name\n }\n }\n }\n}"
data = %{
alias: the_alias,
campaignInput: %{
after: "#{aft}",
chains: nil,
credSources: nil,
excludeChildren: true,
first: fir,
forAdmin: false,
gasTypes: nil,
listType: "Newest",
rewardTypes: nil,
searchString: nil,
statuses: nil,
types: ["Drop", "MysteryBox", "Forge", "MysteryBoxWR", "Airdrop",
"ExternalLink", "OptIn", "OptInEmail", "PowahDrop", "Parent", "Oat",
"Bounty", "Token", "DiscordRole", "Mintlist", "Points", "PointsMysteryBox"]
}
}
Neuron.query(body, data)
end

def query(query_body, url \\ @url) do
request = %HTTPoison.Request{
method: :post,
url: url,
headers: [
{~s|Content-Type|, ~s|application/json|},
{~s|Accept|, ~s|application/json|},
{~s|Connection|, ~s|keep-alive|},
{~s|DNT|, ~s|1|},
],
body: query_body
}
try do
{:ok, %{body: body, status_code: 200}} = HTTPoison.request(request)
{:ok, body |> Poison.decode!() |> ExStructTranslator.to_atom_struct()}
rescue
error ->
{:error, inspect(error)}
end
end

def build_body_query_nft_holder(campaign_id, block, fir, aft) do
Poison.encode!(%{query:
"query NFTHolders {\n campaign(id: \"#{campaign_id}\") {\n nftHolderSnapshot {\n holders(block: #{block}, first: #{fir}, after: \"#{aft}\") {\n list {\n id\n holder\n }\n totalCount\n edges {\n node {\n id\n holder\n }\n cursor\n }\n pageInfo {\n startCursor\n endCursor\n hasNextPage\n hasPreviousPage\n }\n }\n }\n }\n}\n"
})
end

# def build
end
6 changes: 0 additions & 6 deletions lib/tai_shang_micro_faas_system_web/endpoint.ex
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,6 @@ defmodule TaiShangMicroFaasSystemWeb.Endpoint do
gzip: false,
only: ~w(assets fonts images favicon.ico robots.txt)

plug Plug.Static,
at: "/pic_generated",
from: :tai_shang_micro_faas_system,
gzip: false,
only: ~w(assets fonts images favicon.ico robots.txt)

# Code reloading can be explicitly enabled under the
# :code_reloader configuration of your endpoint.
if code_reloading? do
Expand Down
3 changes: 3 additions & 0 deletions mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,9 @@ defmodule TaiShangMicroFaasSystem.MixProject do

# tesla
{:tesla, "~> 1.8.0"},

# graphql client
{:neuron, "~> 5.1.0"}
]
end

Expand Down
1 change: 1 addition & 0 deletions mix.lock
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
"mimerl": {:hex, :mimerl, "1.2.0", "67e2d3f571088d5cfd3e550c383094b47159f3eee8ffa08e64106cdf5e981be3", [:rebar3], [], "hexpm", "f278585650aa581986264638ebf698f8bb19df297f66ad91b18910dfc6e19323"},
"mint": {:hex, :mint, "1.5.1", "8db5239e56738552d85af398798c80648db0e90f343c8469f6c6d8898944fb6f", [:mix], [{:castore, "~> 0.1.0 or ~> 1.0", [hex: :castore, repo: "hexpm", optional: true]}, {:hpax, "~> 0.1.1", [hex: :hpax, repo: "hexpm", optional: false]}], "hexpm", "4a63e1e76a7c3956abd2c72f370a0d0aecddc3976dea5c27eccbecfa5e7d5b1e"},
"mix_erlang_tasks": {:hex, :mix_erlang_tasks, "0.1.0", "36819fec60b80689eb1380938675af215565a89320a9e29c72c70d97512e4649", [:mix], [], "hexpm", "95d2839c422c482a70c08a8702da8242f86b773f8ab6e8602a4eb72da8da04ed"},
"neuron": {:hex, :neuron, "5.1.0", "dd321d5c2d9c03706ee7161ab49f8af634bfd1becb6fb95d8caa28bc95b6c655", [:mix], [{:httpoison, "~> 1.0 or ~> 2.0", [hex: :httpoison, repo: "hexpm", optional: false]}, {:jason, "~> 1.1", [hex: :jason, repo: "hexpm", optional: true]}], "hexpm", "23cddb0e0dd9c0eea247bc5b4bc3e1f8b52dbaf63f1637623920ec0b2385b6ce"},
"nimble_options": {:hex, :nimble_options, "1.0.2", "92098a74df0072ff37d0c12ace58574d26880e522c22801437151a159392270e", [:mix], [], "hexpm", "fd12a8db2021036ce12a309f26f564ec367373265b53e25403f0ee697380f1b8"},
"nimble_parsec": {:hex, :nimble_parsec, "1.3.1", "2c54013ecf170e249e9291ed0a62e5832f70a476c61da16f6aac6dca0189f2af", [:mix], [], "hexpm", "2682e3c0b2eb58d90c6375fc0cc30bc7be06f365bf72608804fb9cffa5e1b167"},
"nimble_pool": {:hex, :nimble_pool, "1.0.0", "5eb82705d138f4dd4423f69ceb19ac667b3b492ae570c9f5c900bb3d2f50a847", [:mix], [], "hexpm", "80be3b882d2d351882256087078e1b1952a28bf98d0a287be87e4a24a710b67a"},
Expand Down
File renamed without changes
1 change: 1 addition & 0 deletions priv/static/images/8942c468fcfffc37a550.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions priv/static/images/a123e29d5a4ae3b12345.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added priv/static/images/doge.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added priv/static/images/girl.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions priv/static/images/result.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added priv/static/images/result.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added priv/static/images/result_re.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added priv/static/images/result_re_3.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added priv/static/images/sketch_example.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added priv/static/images/sketch_example_2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit e5b606e

Please sign in to comment.