willn9 commited on
Commit
cc520b9
·
verified ·
1 Parent(s): a93bb5e

Rename app_openai.py to app.py

Browse files
Files changed (1) hide show
  1. app_openai.py → app.py +51 -0
app_openai.py → app.py RENAMED
@@ -39,3 +39,54 @@ def respond(
39
  messages.append({"role": "user", "content": message})
40
 
41
  # Generate and stream response
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
39
  messages.append({"role": "user", "content": message})
40
 
41
  # Generate and stream response
42
+ response_text = ""
43
+ try:
44
+ response = client.chat.completions.create(
45
+ model="gpt-4o-mini", # or "gpt-4o" when mini is unavailable
46
+ messages=messages,
47
+ max_tokens=max_tokens,
48
+ temperature=temperature,
49
+ top_p=top_p,
50
+ stream=True,
51
+ )
52
+ for chunk in response:
53
+ if chunk.choices and chunk.choices[0].delta.content:
54
+ token = chunk.choices[0].delta.content
55
+ response_text += token
56
+ yield response_text
57
+ except Exception as e:
58
+ yield f"❌ An error occurred: {str(e)}"
59
+
60
+ # Define the Gradio interface
61
+ demo = gr.ChatInterface(
62
+ fn=respond,
63
+ additional_inputs=[
64
+ gr.Textbox(
65
+ value="You are a friendly Chatbot, a career coach and a talented copywriter. You are trying to help a user write a cover letter for a specific role, employer organization and job Ad - based on user input. Include tips if some items are missing.",
66
+ label="Instructions to Bot",
67
+ ),
68
+ gr.Textbox(label="Role, Industry, Employer and Summary of Job Ad", placeholder="Describe the role, industry, employer and include a summary of the job Ad that you are applying to."),
69
+ gr.Textbox(
70
+ label="Education and Professional Experience",
71
+ placeholder="Provide a Summary of your Education and Professional Experience",
72
+ ),
73
+ gr.Textbox(
74
+ label="Passion",
75
+ placeholder="Why are you Passionate about this Role and or Organization",
76
+ ),
77
+ gr.Textbox(
78
+ label="Fit",
79
+ placeholder="Why are you a good fit for this role?",
80
+ ),
81
+ gr.Textbox(label="Anecdotes", placeholder="Tell a few anecdotes from your career situations or key problems you solved in previous roles that may show that you will add great value to this organization"),
82
+ gr.Slider(minimum=1, maximum=2048, value=512, step=1, label="Max new tokens"),
83
+ gr.Slider(minimum=0.1, maximum=4.0, value=0.7, step=0.1, label="Temperature"),
84
+ gr.Slider(minimum=0.1, maximum=1.0, value=0.95, step=0.05, label="Top-p (nucleus sampling)"),
85
+ ],
86
+ title="Cover Letter Writer!",
87
+ description="This AI-powered App creates a customized cover letter to best suit a specific role, industry, employer and job ad. Powered by OpenAI GPT-4o. Developed by wn. Disclaimer: AI makes mistakes. Use with caution and at your own risk!",
88
+ type="messages",
89
+ )
90
+
91
+ if __name__ == "__main__":
92
+ demo.launch()