Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,46 +1,39 @@
|
|
| 1 |
-
import os
|
| 2 |
import gradio as gr
|
| 3 |
import requests
|
|
|
|
|
|
|
| 4 |
|
| 5 |
-
#
|
| 6 |
-
|
|
|
|
| 7 |
|
| 8 |
def generate_text(prompt):
|
|
|
|
| 9 |
headers = {
|
| 10 |
-
"Authorization": f"Bearer {
|
| 11 |
"Content-Type": "application/json"
|
| 12 |
}
|
| 13 |
data = {
|
| 14 |
"prompt": prompt,
|
| 15 |
-
"max_tokens": 150
|
|
|
|
| 16 |
}
|
| 17 |
-
|
|
|
|
| 18 |
|
| 19 |
if response.status_code == 200:
|
| 20 |
-
return response.json().get("text", "No text
|
| 21 |
else:
|
| 22 |
-
return "Error:
|
| 23 |
-
|
| 24 |
-
def suggest_improvement(text):
|
| 25 |
-
# Placeholder for suggestion logic
|
| 26 |
-
return f"Suggestion for improvement: {text} could be enhanced by adding more details."
|
| 27 |
-
|
| 28 |
-
with gr.Blocks() as demo:
|
| 29 |
-
gr.Markdown("## Text Generation and Improvement Suggestions")
|
| 30 |
-
|
| 31 |
-
with gr.Row():
|
| 32 |
-
with gr.Column():
|
| 33 |
-
prompt_input = gr.Textbox(label="Enter your prompt", placeholder="Type your text here...")
|
| 34 |
-
generate_button = gr.Button("Generate Text")
|
| 35 |
-
output_text = gr.Textbox(label="Generated Text", interactive=False)
|
| 36 |
-
|
| 37 |
-
with gr.Column():
|
| 38 |
-
improvement_input = gr.Textbox(label="Enter text for suggestions", placeholder="Type your text here...")
|
| 39 |
-
suggest_button = gr.Button("Get Suggestions")
|
| 40 |
-
suggestion_output = gr.Textbox(label="Improvement Suggestions", interactive=False)
|
| 41 |
|
| 42 |
-
|
| 43 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 44 |
|
| 45 |
if __name__ == "__main__":
|
| 46 |
-
|
|
|
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
import requests
|
| 3 |
+
import os
|
| 4 |
+
from dotenv import load_dotenv
|
| 5 |
|
| 6 |
+
# Load environment variables
|
| 7 |
+
load_dotenv()
|
| 8 |
+
BLACKBOX_API_KEY = os.getenv("sk-Ro0qnkz8DKLBGsuvsDRPaQ")
|
| 9 |
|
| 10 |
def generate_text(prompt):
|
| 11 |
+
# Call the Blackbox AI API
|
| 12 |
headers = {
|
| 13 |
+
"Authorization": f"Bearer {BLACKBOX_API_KEY}",
|
| 14 |
"Content-Type": "application/json"
|
| 15 |
}
|
| 16 |
data = {
|
| 17 |
"prompt": prompt,
|
| 18 |
+
"max_tokens": 150, # Adjust as needed
|
| 19 |
+
"temperature": 0.7 # Adjust as needed
|
| 20 |
}
|
| 21 |
+
|
| 22 |
+
response = requests.post("https://api.blackbox.ai/generate", headers=headers, json=data)
|
| 23 |
|
| 24 |
if response.status_code == 200:
|
| 25 |
+
return response.json().get("text", "No response text found.")
|
| 26 |
else:
|
| 27 |
+
return f"Error: {response.status_code} - {response.text}"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 28 |
|
| 29 |
+
# Create Gradio interface
|
| 30 |
+
iface = gr.Interface(
|
| 31 |
+
fn=generate_text,
|
| 32 |
+
inputs=gr.Textbox(lines=2, placeholder="Enter your prompt here..."),
|
| 33 |
+
outputs="text",
|
| 34 |
+
title="Text-to-Text Copilot",
|
| 35 |
+
description="A copilot for text generation that learns from coding patterns and provides suggestions."
|
| 36 |
+
)
|
| 37 |
|
| 38 |
if __name__ == "__main__":
|
| 39 |
+
iface.launch()
|