Spaces:
Sleeping
Sleeping
| 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() | |