superbsaeed commited on
Commit
49afb29
·
verified ·
1 Parent(s): 8d2c2ee

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +62 -0
app.py ADDED
@@ -0,0 +1,62 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+
3
+ def generate_linkedin_post(topic, keywords, tone, call_to_action, special_request):
4
+ """Generates a LinkedIn post using the Groq API based on user inputs."""
5
+
6
+ if not topic:
7
+ return "Please provide a topic for the LinkedIn post.\n\nExample: 'The future of AI in healthcare'"
8
+
9
+ # Construct the prompt for the Groq API
10
+ prompt = f"""Generate a professional and engaging LinkedIn post about '{topic}'.
11
+ """
12
+ if keywords:
13
+ prompt += f"Include keywords like {keywords}.\n"
14
+ if tone:
15
+ prompt += f"The tone should be {tone}.\n"
16
+ if call_to_action:
17
+ prompt += f"Conclude with a call to action: '{call_to_action}'\n"
18
+ if special_request:
19
+ prompt += f"Also consider this special request: '{special_request}'.\n"
20
+
21
+ prompt += "\nThe post should be concise, impactful, and suitable for a professional audience."
22
+
23
+ try:
24
+ # Make the API call to Groq
25
+ chat_completion = groq_client.chat.completions.create(
26
+ messages=[
27
+ {
28
+ "role": "user",
29
+ "content": prompt,
30
+ }
31
+ ],
32
+ model=groq_model_name,
33
+ temperature=0.7, # Adjust for creativity: 0.0 (less creative) to 1.0 (more creative)
34
+ max_tokens=500 # Set a maximum length for the generated post
35
+ )
36
+ # Extract the generated content
37
+ return chat_completion.choices[0].message.content
38
+ except Exception as e:
39
+ return f"An error occurred while generating the post: {e}\n\nPlease ensure your GROQ_API_KEY is correctly set in Colab secrets and you have internet access."
40
+
41
+
42
+ # Create the Gradio interface
43
+ # We define the inputs (textboxes for topic, keywords, etc.) and the output (a textbox for the generated post)
44
+ iface = gr.Interface(
45
+ fn=generate_linkedin_post, # The function to run when the user clicks 'Submit'
46
+ inputs=[
47
+ gr.Textbox(label="Topic (required)", placeholder="e.g., AI in education, New programming language features"),
48
+ gr.Textbox(label="Keywords (optional)", placeholder="e.g., personalized learning, future skills, innovation"),
49
+ gr.Textbox(label="Tone (optional)", placeholder="e.g., professional and inspiring, informative, enthusiastic"),
50
+ gr.Textbox(label="Call to Action (optional)", placeholder="e.g., Share your thoughts in the comments!, Visit our website!"),
51
+ gr.Textbox(label="Special Request (optional)", placeholder="e.g., Make it exactly 3 sentences, include a specific hashtag #FutureOfWork")
52
+ ],
53
+ outputs=gr.Textbox(label="Generated LinkedIn Post", lines=10, show_copy_button=True), # Output text box with 10 lines height, explicitly showing copy button
54
+ title=" I will help you create a Linkedin Post ",
55
+ description="Generate professional and engaging LinkedIn posts using Saeed's Bot. Fill in the details below and click 'Submit' to get your post"
56
+ )
57
+
58
+ # Launch the Gradio app
59
+ # `share=True` creates a public, shareable link that works for 72 hours.
60
+ # For local development, `share=False` would launch on your local machine.
61
+ print("Launching Gradio app...")
62
+ iface.launch(share=True)