varunkuntal's picture
Added main app
7ea1edb
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 = "https://api-inference.huggingface.co/models/gpt2"
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()