MalikShehram commited on
Commit
dfdbcb5
·
verified ·
1 Parent(s): 0c0a32c

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +46 -0
app.py ADDED
@@ -0,0 +1,46 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ import gradio as gr
3
+ import requests
4
+
5
+ # Set your Black Box API key
6
+ API_KEY = os.getenv("sk-Ro0qnkz8DKLBGsuvsDRPaQ")
7
+
8
+ def generate_text(prompt):
9
+ headers = {
10
+ "Authorization": f"Bearer {API_KEY}",
11
+ "Content-Type": "application/json"
12
+ }
13
+ data = {
14
+ "prompt": prompt,
15
+ "max_tokens": 150
16
+ }
17
+ response = requests.post("https://api.blackbox.com/generate", headers=headers, json=data)
18
+
19
+ if response.status_code == 200:
20
+ return response.json().get("text", "No text generated.")
21
+ else:
22
+ return "Error: " + response.text
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
+ generate_button.click(generate_text, inputs=prompt_input, outputs=output_text)
43
+ suggest_button.click(suggest_improvement, inputs=improvement_input, outputs=suggestion_output)
44
+
45
+ if __name__ == "__main__":
46
+ demo.launch()