Spaces:
Runtime error
Runtime error
| #!/usr/bin/env python3 | |
| """ | |
| Minimal version of AutoStartup.ai for debugging HuggingFace deployment | |
| """ | |
| import gradio as gr | |
| import os | |
| def test_environment(): | |
| """Test if environment variables are properly set""" | |
| api_key = os.getenv("OPENAI_API_KEY") | |
| endpoint = os.getenv("OPENAI_API_ENDPOINT") | |
| model = os.getenv("OPENAI_MODEL") | |
| if not api_key: | |
| return "β OPENAI_API_KEY not found" | |
| if not endpoint: | |
| return "β OPENAI_API_ENDPOINT not found" | |
| if not model: | |
| return "β OPENAI_MODEL not found" | |
| return f"β Environment OK\n- API Key: {api_key[:10]}...\n- Endpoint: {endpoint}\n- Model: {model}" | |
| def simple_generate(query): | |
| """Simple test function""" | |
| if not query.strip(): | |
| return "Please enter a query" | |
| try: | |
| from openai import OpenAI | |
| client = OpenAI( | |
| api_key=os.getenv("OPENAI_API_KEY"), | |
| base_url=os.getenv("OPENAI_API_ENDPOINT") | |
| ) | |
| response = client.chat.completions.create( | |
| model=os.getenv("OPENAI_MODEL"), | |
| messages=[ | |
| {"role": "system", "content": "You are a helpful startup idea generator."}, | |
| {"role": "user", "content": f"Generate a simple startup idea for: {query}"} | |
| ], | |
| max_tokens=200 | |
| ) | |
| return f"β API Working!\n\nIdea: {response.choices[0].message.content}" | |
| except Exception as e: | |
| return f"β Error: {str(e)}" | |
| # Simple Gradio interface for testing | |
| with gr.Blocks(title="AutoStartup.ai - Debug Mode") as demo: | |
| gr.Markdown( | |
| """ | |
| # π§ AutoStartup.ai - Debug Mode | |
| This is a minimal version to test the deployment and API connectivity. | |
| """ | |
| ) | |
| with gr.Row(): | |
| with gr.Column(): | |
| env_status = gr.Textbox( | |
| label="Environment Status", | |
| value=test_environment(), | |
| interactive=False, | |
| lines=5 | |
| ) | |
| query_input = gr.Textbox( | |
| label="Test Query", | |
| placeholder="Enter a market problem or industry focus...", | |
| lines=3 | |
| ) | |
| test_button = gr.Button("π§ͺ Test API Connection", variant="primary") | |
| with gr.Column(): | |
| result_output = gr.Textbox( | |
| label="Test Result", | |
| interactive=False, | |
| lines=10 | |
| ) | |
| test_button.click( | |
| fn=simple_generate, | |
| inputs=[query_input], | |
| outputs=[result_output] | |
| ) | |
| if __name__ == "__main__": | |
| demo.launch() |