natgluons commited on
Commit
f55f937
Β·
1 Parent(s): 99ec0c6

Ready for Hugging Face Spaces deployment

Browse files
pickup-line-generator/.env.production ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ NEXT_PUBLIC_HF_TOKEN=your_huggingface_token
2
+ NEXT_PUBLIC_MODEL_ID=HuggingFaceTB/SmolLM-135M
3
+ NODE_ENV=production
pickup-line-generator/app.py ADDED
@@ -0,0 +1,19 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from pathlib import Path
2
+ import subprocess
3
+ import sys
4
+
5
+ def setup():
6
+ # Install dependencies
7
+ subprocess.check_call([sys.executable, "-m", "pip", "install", "-r", "requirements.txt"])
8
+
9
+ # Install npm dependencies and build Next.js app
10
+ subprocess.check_call(["npm", "install"])
11
+ subprocess.check_call(["npm", "run", "build"])
12
+
13
+ def main():
14
+ # Start the Next.js server
15
+ subprocess.check_call(["npm", "start"])
16
+
17
+ if __name__ == "__main__":
18
+ setup()
19
+ main()
pickup-line-generator/app/api/generate/route.ts CHANGED
@@ -1,58 +1,29 @@
1
  import { NextResponse } from 'next/server';
2
- import { getVibeGuidance } from '@/lib/prompts';
3
 
4
  export async function POST(request: Request) {
5
- // Handle CORS
6
- if (request.method === 'OPTIONS') {
7
- return new NextResponse(null, {
8
- status: 200,
 
 
9
  headers: {
10
- 'Access-Control-Allow-Origin': '*',
11
- 'Access-Control-Allow-Methods': 'GET, POST, PUT, DELETE, OPTIONS',
12
- 'Access-Control-Allow-Headers': 'Content-Type, Authorization',
13
  },
 
14
  });
15
- }
16
 
17
- try {
18
- const { vibe } = await request.json();
19
-
20
- // Get the vibe guidance
21
- const vibeGuide = getVibeGuidance(vibe);
22
-
23
- // Create the prompt
24
- const prompt = `Instructions: Generate a pickup line with a ${vibe} vibe.\n${vibeGuide}`;
25
-
26
- // TODO: Replace this with actual model inference
27
- // For now, return a mock response
28
- const mockResponses = {
29
- romantic: "Are you a magician? Because whenever I look at you, everyone else disappears. ❀️",
30
- cheesy: "Are you a parking ticket? Because you've got FINE written all over you! 😏",
31
- nerdy: "Are you made of copper and tellurium? Because you're Cu-Te! πŸ”¬",
32
- cringe: "Are you a dictionary? Because you're adding meaning to my life! πŸ“š",
33
- flirty: "Is your name Google? Because you've got everything I've been searching for! 😏"
34
- };
35
 
36
- const response = NextResponse.json({ pickupLine: mockResponses[vibe as keyof typeof mockResponses] });
37
-
38
- // Add CORS headers to the response
39
- response.headers.set('Access-Control-Allow-Origin', '*');
40
- response.headers.set('Access-Control-Allow-Methods', 'GET, POST, PUT, DELETE, OPTIONS');
41
- response.headers.set('Access-Control-Allow-Headers', 'Content-Type, Authorization');
42
-
43
- return response;
44
  } catch (error) {
45
  console.error('Error generating pickup line:', error);
46
- const errorResponse = NextResponse.json(
47
  { error: 'Failed to generate pickup line' },
48
  { status: 500 }
49
  );
50
-
51
- // Add CORS headers to the error response
52
- errorResponse.headers.set('Access-Control-Allow-Origin', '*');
53
- errorResponse.headers.set('Access-Control-Allow-Methods', 'GET, POST, PUT, DELETE, OPTIONS');
54
- errorResponse.headers.set('Access-Control-Allow-Headers', 'Content-Type, Authorization');
55
-
56
- return errorResponse;
57
  }
58
  }
 
1
  import { NextResponse } from 'next/server';
 
2
 
3
  export async function POST(request: Request) {
4
+ try {
5
+ const body = await request.json();
6
+
7
+ // Forward the request to our model server
8
+ const response = await fetch(`${process.env.NEXT_PUBLIC_API_URL}/generate`, {
9
+ method: 'POST',
10
  headers: {
11
+ 'Content-Type': 'application/json',
 
 
12
  },
13
+ body: JSON.stringify(body),
14
  });
 
15
 
16
+ if (!response.ok) {
17
+ throw new Error('Failed to generate pickup line');
18
+ }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
19
 
20
+ const data = await response.json();
21
+ return NextResponse.json(data);
 
 
 
 
 
 
22
  } catch (error) {
23
  console.error('Error generating pickup line:', error);
24
+ return NextResponse.json(
25
  { error: 'Failed to generate pickup line' },
26
  { status: 500 }
27
  );
 
 
 
 
 
 
 
28
  }
29
  }
pickup-line-generator/next.config.js CHANGED
@@ -1,7 +1,11 @@
1
  /** @type {import('next').NextConfig} */
2
  const nextConfig = {
 
3
  reactStrictMode: true,
4
  swcMinify: true,
 
 
 
5
  }
6
 
7
  module.exports = nextConfig
 
1
  /** @type {import('next').NextConfig} */
2
  const nextConfig = {
3
+ output: 'standalone',
4
  reactStrictMode: true,
5
  swcMinify: true,
6
+ experimental: {
7
+ serverActions: true,
8
+ },
9
  }
10
 
11
  module.exports = nextConfig
pickup-line-generator/requirements.txt ADDED
@@ -0,0 +1,6 @@
 
 
 
 
 
 
 
1
+ torch>=2.0.0
2
+ transformers>=4.30.0
3
+ huggingface-hub>=0.19.0
4
+ numpy>=1.24.0
5
+ tqdm>=4.65.0
6
+ typing-extensions>=4.5.0