File size: 3,318 Bytes
a74b879
0e3cfb9
a74b879
0e3cfb9
a74b879
 
 
 
 
0e3cfb9
a00029a
0e3cfb9
588dd1c
7f1cd07
588dd1c
0e3cfb9
7f1cd07
588dd1c
a74b879
b4a3e73
81188cd
 
 
83d71f5
81188cd
 
 
 
 
 
 
 
 
 
 
a00029a
81188cd
 
 
 
 
 
 
a00029a
0e3cfb9
588dd1c
 
 
 
b4a3e73
588dd1c
 
 
b4a3e73
588dd1c
 
b4a3e73
588dd1c
 
b4a3e73
588dd1c
 
 
 
 
b4a3e73
 
588dd1c
b4a3e73
588dd1c
0e3cfb9
b4a3e73
 
 
 
588dd1c
b4a3e73
 
 
 
 
 
588dd1c
 
 
b4a3e73
588dd1c
a74b879
588dd1c
b4a3e73
a00029a
 
 
c170ed5
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
"""
Moharek GEO Platform - Hugging Face Space
"""

import sys
from pathlib import Path

sys.path.insert(0, str(Path(__file__).parent))

import gradio as gr
from fastapi import FastAPI, Request
from fastapi.staticfiles import StaticFiles
from fastapi.responses import FileResponse

# Import API
from server.api import app as fastapi_app

# Frontend path
frontend_path = Path(__file__).parent / "frontend"

# Serve frontend files - catch-all handler
@fastapi_app.get("/{full_path:path}")
async def serve_frontend(full_path: str):
    # Remove /app/ prefix if present
    if full_path.startswith('app/'):
        full_path = full_path[4:]
    
    # Default to index.html for root
    if not full_path or full_path == '/':
        full_path = 'index.html'
    
    # Try to serve the file
    file_path = frontend_path / full_path
    
    if file_path.exists() and file_path.is_file():
        return FileResponse(str(file_path))
    
    # If no extension, try adding .html
    if '.' not in full_path:
        html_path = frontend_path / f"{full_path}.html"
        if html_path.exists():
            return FileResponse(str(html_path))
    
    return {"ok": False, "error": "not found"}

# Gradio interface
with gr.Blocks(title="Moharek GEO Platform") as demo:
    gr.Markdown("# 🚀 Moharek GEO Platform")
    gr.Markdown("## منصة تحسين محركات البحث بالذكاء الاصطناعي")
    
    with gr.Row():
        website_url = gr.Textbox(label="رابط الموقع", placeholder="https://example.com")
        org_name = gr.Textbox(label="اسم الشركة", placeholder="اسم شركتك")
    
    max_pages = gr.Slider(10, 100, 50, step=10, label="عدد الصفحات")
    analyze_btn = gr.Button("🚀 ابدأ التحليل", variant="primary")
    
    output_status = gr.Textbox(label="حالة التحليل", lines=3)
    output_json = gr.JSON(label="نتائج التحليل")
    
    gr.Markdown("""
    ### 🌐 الوصول الكامل
    - [لوحة التحكم](/portal.html)
    - [الصفحة الرئيسية](/index.html)
    - [API Docs](/api/docs)
    """)
    
    def analyze(url, name, pages):
        if not url or not url.startswith('http'):
            return "❌ الرجاء إدخال رابط صحيح", None
        
        try:
            import requests
            response = requests.post(
                "http://localhost:7860/api/jobs",
                json={"url": url, "org_name": name or "Unknown", "org_url": url, "max_pages": int(pages), "runs": 1},
                timeout=30
            )
            
            if response.status_code == 200:
                data = response.json()
                if data.get("ok"):
                    return f"✅ تم إنشاء التحليل! Job ID: {data.get('job_id')}", data
                return f"❌ خطأ: {data.get('error')}", None
            return f"❌ خطأ: {response.status_code}", None
        except Exception as e:
            return f"❌ خطأ: {str(e)}", None
    
    analyze_btn.click(analyze, [website_url, org_name, max_pages], [output_status, output_json])

# Mount Gradio to FastAPI at /gradio
app = gr.mount_gradio_app(fastapi_app, demo, path="/gradio")

if __name__ == "__main__":
    import uvicorn
    uvicorn.run(app, host="0.0.0.0", port=7860)