File size: 1,665 Bytes
dfdbcb5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import os
import gradio as gr
import requests

# Set your Black Box API key
API_KEY = os.getenv("sk-Ro0qnkz8DKLBGsuvsDRPaQ")

def generate_text(prompt):
    headers = {
        "Authorization": f"Bearer {API_KEY}",
        "Content-Type": "application/json"
    }
    data = {
        "prompt": prompt,
        "max_tokens": 150
    }
    response = requests.post("https://api.blackbox.com/generate", headers=headers, json=data)
    
    if response.status_code == 200:
        return response.json().get("text", "No text generated.")
    else:
        return "Error: " + response.text

def suggest_improvement(text):
    # Placeholder for suggestion logic
    return f"Suggestion for improvement: {text} could be enhanced by adding more details."

with gr.Blocks() as demo:
    gr.Markdown("## Text Generation and Improvement Suggestions")
    
    with gr.Row():
        with gr.Column():
            prompt_input = gr.Textbox(label="Enter your prompt", placeholder="Type your text here...")
            generate_button = gr.Button("Generate Text")
            output_text = gr.Textbox(label="Generated Text", interactive=False)
        
        with gr.Column():
            improvement_input = gr.Textbox(label="Enter text for suggestions", placeholder="Type your text here...")
            suggest_button = gr.Button("Get Suggestions")
            suggestion_output = gr.Textbox(label="Improvement Suggestions", interactive=False)

    generate_button.click(generate_text, inputs=prompt_input, outputs=output_text)
    suggest_button.click(suggest_improvement, inputs=improvement_input, outputs=suggestion_output)

if __name__ == "__main__":
    demo.launch()