Spaces:
Sleeping
Sleeping
| import os | |
| import httpx | |
| async def generate_image_script(text): | |
| try: | |
| with httpx.Client(timeout=10.0) as client: | |
| response = client.post( | |
| url="https://openrouter.ai/api/v1/chat/completions", | |
| headers={ | |
| "Authorization": f"Bearer {os.getenv('OPENROUTER_API_KEY')}", | |
| "Content-Type": "application/json", | |
| "HTTP-Referer": "https://sreepathi-ravikumar-sample.hf.space", | |
| "X-Title": "Educational AI Assistant" | |
| }, | |
| json={ | |
| "model": "deepseek/deepseek-chat-v3-0324:free", | |
| "messages": [{ | |
| "role": "user", | |
| "content": f"""topic:\n{text} \n prompt :\n *Educational Video Image Search Prompt Generator* | |
| *Task:* | |
| - You provide a topic or paragraph (e.g., "AC generator"). | |
| - I return *literal, search-friendly terms* for finding concrete 16:9 images (480p/720p). | |
| *Rules Applied:* | |
| 1. *Concrete Objects/Scenes Only* (e.g., "rotating copper coil in magnetic field" not "electromagnetic induction"). | |
| 2. *Natural Language* (phrases you’d actually type into Google Images). | |
| 3. *No Abstraction* (avoid "illustration," "diagram" unless critical). | |
| 4. *but that image easily available on internet same thing that related to that topics so that simple image that script | |
| *Output Format:* | |
| - Bulletless list of 3–7 exact search terms. | |
| --- | |
| ### *Example Usage:* | |
| *Your Input:* | |
| "Generate image search prompts for this topic: AC generator" | |
| *My Output:* | |
| rotating copper coil in magnetic field | |
| AC generator industrial machine close-up | |
| sinusoidal alternating current waveform graph | |
| slip rings and carbon brushes close-up | |
| power plant turbine generating electricity """ | |
| }], | |
| "temperature": 0.7, | |
| "max_tokens": 500 | |
| } | |
| ) | |
| response.raise_for_status() | |
| return response.json()['choices'][0]['message']['content'] | |
| except Exception as e: | |
| return f"Error generating answer: {str(e)}" |