sreepathi-ravikumar commited on
Commit
446bbff
·
verified ·
1 Parent(s): d1d8593

Create image_scripter.py

Browse files
Files changed (1) hide show
  1. image_scripter.py +53 -0
image_scripter.py ADDED
@@ -0,0 +1,53 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ import httpx
3
+
4
+ def generate_image_script(text):
5
+ try:
6
+ with httpx.Client(timeout=10.0) as client:
7
+ response = client.post(
8
+ url="https://openrouter.ai/api/v1/chat/completions",
9
+ headers={
10
+ "Authorization": f"Bearer {os.getenv('OPENROUTER_API_KEY')}",
11
+ "Content-Type": "application/json",
12
+ "HTTP-Referer": "https://sreepathi-ravikumar-sample.hf.space",
13
+ "X-Title": "Educational AI Assistant"
14
+ },
15
+ json={
16
+ "model": "deepseek/deepseek-chat-v3-0324:free",
17
+ "messages": [{
18
+ "role": "user",
19
+ "content": f"""topic:\n{text} \n prompt :\n *Educational Video Image Search Prompt Generator*
20
+ *Task:*
21
+ - You provide a topic or paragraph (e.g., "AC generator").
22
+ - I return *literal, search-friendly terms* for finding concrete 16:9 images (480p/720p).
23
+
24
+ *Rules Applied:*
25
+ 1. *Concrete Objects/Scenes Only* (e.g., "rotating copper coil in magnetic field" not "electromagnetic induction").
26
+ 2. *Natural Language* (phrases you’d actually type into Google Images).
27
+ 3. *No Abstraction* (avoid "illustration," "diagram" unless critical).
28
+
29
+ *Output Format:*
30
+ - Bulletless list of 3–7 exact search terms.
31
+
32
+ ---
33
+
34
+ ### *Example Usage:*
35
+ *Your Input:*
36
+ "Generate image search prompts for this topic: AC generator"
37
+
38
+ *My Output:*
39
+ rotating copper coil in magnetic field
40
+ AC generator industrial machine close-up
41
+ sinusoidal alternating current waveform graph
42
+ slip rings and carbon brushes close-up
43
+ power plant turbine generating electricity """
44
+ }],
45
+ "temperature": 0.7,
46
+ "max_tokens": 2000
47
+ }
48
+ )
49
+ response.raise_for_status()
50
+ return response.json()['choices'][0]['message']['content']
51
+
52
+ except Exception as e:
53
+ return f"Error generating answer: {str(e)}"