File size: 1,558 Bytes
7ea1edb
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
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()