Spaces:
Runtime error
Runtime error
Commit
·
7ea1edb
1
Parent(s):
e4623d8
Added main app
Browse files
app.py
ADDED
@@ -0,0 +1,53 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
import requests
|
3 |
+
import json
|
4 |
+
|
5 |
+
def txt2img1(text):
|
6 |
+
url = "https://stablediffusionapi.com/api/v3/text2img"
|
7 |
+
|
8 |
+
payload = json.dumps({
|
9 |
+
"key": "qXpCKAkXLdKWb2sqcMlMzB0Q3gqHEggJIXxspJzHIVHUy6H9S060RN0BNGqj",
|
10 |
+
"prompt": text,
|
11 |
+
"negative_prompt": None,
|
12 |
+
"width": "512",
|
13 |
+
"height": "512",
|
14 |
+
"samples": "1",
|
15 |
+
"num_inference_steps": "20",
|
16 |
+
"seed": None,
|
17 |
+
"guidance_scale": 7.5,
|
18 |
+
"safety_checker": "yes",
|
19 |
+
"multi_lingual": "no",
|
20 |
+
"panorama": "no",
|
21 |
+
"self_attention": "no",
|
22 |
+
"upscale": "no",
|
23 |
+
"embeddings_model": "embeddings_model_id",
|
24 |
+
"webhook": None,
|
25 |
+
"track_id": None
|
26 |
+
})
|
27 |
+
|
28 |
+
headers = {
|
29 |
+
'Content-Type': 'application/json'
|
30 |
+
}
|
31 |
+
|
32 |
+
response = requests.request("POST", url, headers=headers, data=payload)
|
33 |
+
response_dict = response.json()
|
34 |
+
|
35 |
+
return response_dict['output'][0]
|
36 |
+
|
37 |
+
def txt2txt(text):
|
38 |
+
API_TOKEN = "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"
|
39 |
+
API_URL = "https://api-inference.huggingface.co/models/gpt2"
|
40 |
+
headers = {"Authorization": f"Bearer {API_TOKEN}"}
|
41 |
+
|
42 |
+
def query(payload):
|
43 |
+
response = requests.post(API_URL, headers=headers, json=payload)
|
44 |
+
return response.json()
|
45 |
+
|
46 |
+
output = query({"inputs": text})
|
47 |
+
return output[0]['generated_text']
|
48 |
+
|
49 |
+
iface = gr.Interface(fn=txt2img1, inputs="text", outputs="image", title="Text to Image")
|
50 |
+
iface.launch()
|
51 |
+
|
52 |
+
iface2 = gr.Interface(fn=txt2txt, inputs="text", outputs="text", title="Text to Text")
|
53 |
+
iface2.launch()
|