Spaces:
Runtime error
Runtime error
| import gradio as gr | |
| import requests | |
| import json | |
| def txt2img1(text): | |
| url = "https://stablediffusionapi.com/api/v3/text2img" | |
| payload = json.dumps({ | |
| "key": "qXpCKAkXLdKWb2sqcMlMzB0Q3gqHEggJIXxspJzHIVHUy6H9S060RN0BNGqj", | |
| "prompt": text, | |
| "negative_prompt": None, | |
| "width": "512", | |
| "height": "512", | |
| "samples": "1", | |
| "num_inference_steps": "20", | |
| "seed": None, | |
| "guidance_scale": 7.5, | |
| "safety_checker": "yes", | |
| "multi_lingual": "no", | |
| "panorama": "no", | |
| "self_attention": "no", | |
| "upscale": "no", | |
| "embeddings_model": "embeddings_model_id", | |
| "webhook": None, | |
| "track_id": None | |
| }) | |
| headers = { | |
| 'Content-Type': 'application/json' | |
| } | |
| response = requests.request("POST", url, headers=headers, data=payload) | |
| response_dict = response.json() | |
| return response_dict['output'][0] | |
| def txt2txt(text): | |
| API_TOKEN = "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" | |
| API_URL = "/static-proxy?url=https%3A%2F%2Fapi-inference.huggingface.co%2Fmodels%2Fgpt2%26quot%3B%3C%2Fspan%3E | |
| headers = {"Authorization": f"Bearer {API_TOKEN}"} | |
| def query(payload): | |
| response = requests.post(API_URL, headers=headers, json=payload) | |
| return response.json() | |
| output = query({"inputs": text}) | |
| return output[0]['generated_text'] | |
| iface = gr.Interface(fn=txt2img1, inputs="text", outputs="image", title="Text to Image") | |
| iface.launch() | |
| iface2 = gr.Interface(fn=txt2txt, inputs="text", outputs="text", title="Text to Text") | |
| iface2.launch() |