ANXLOG commited on
Commit
9d91c12
·
verified ·
1 Parent(s): 27905ae

Upload 3 files

Browse files
hf_space_minimal/README.md ADDED
@@ -0,0 +1,42 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # LOGOS Computational System
2
+
3
+ A vision analysis system integrated with LM Studio for computational processing.
4
+
5
+ ## Features
6
+
7
+ - **Vision Analysis**: Upload images for AI-powered analysis
8
+ - **LM Studio Integration**: Direct connection to local models
9
+ - **Real-time Processing**: Fast response times with optimized workflows
10
+ - **Custom Prompts**: Tailor analysis to your specific needs
11
+
12
+ ## Model Configuration
13
+
14
+ - **Model**: google/gemma-3-4b
15
+ - **LM Studio**: http://192.168.0.105:1234
16
+ - **Framework**: Gradio 4.44.0
17
+
18
+ ## Usage
19
+
20
+ 1. Upload an image or use the "Create Test Image" button
21
+ 2. Enter a custom analysis prompt or use the default
22
+ 3. Click "Analyze Image" to process
23
+ 4. View results in real-time
24
+
25
+ ## Technical Details
26
+
27
+ - **Backend**: Python with Gradio interface
28
+ - **Vision Model**: Google Gemma 3-4B via LM Studio
29
+ - **Image Processing**: PIL and OpenCV
30
+ - **API**: RESTful HTTP requests to LM Studio
31
+
32
+ ## Requirements
33
+
34
+ - Python 3.8+
35
+ - Gradio >=4.0.0
36
+ - Requests >=2.28.0
37
+ - Pillow >=9.0.0
38
+ - LM Studio with google/gemma-3-4b model
39
+
40
+ ---
41
+
42
+ *LOGOS Computational System v1.0*
hf_space_minimal/app.py ADDED
@@ -0,0 +1,177 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env python3
2
+ """
3
+ LOGOS Hugging Face Space - Clean Deployment
4
+ """
5
+
6
+ import gradio as gr
7
+ import requests
8
+ import base64
9
+ import time
10
+ from io import BytesIO
11
+ from PIL import Image, ImageDraw
12
+
13
+ def analyze_image(image, prompt="Analyze this image"):
14
+ """Analyze image with LM Studio"""
15
+ if image is None:
16
+ return "Please upload an image first."
17
+
18
+ try:
19
+ # Convert PIL to RGB if needed
20
+ if image.mode != 'RGB':
21
+ image = image.convert('RGB')
22
+
23
+ # Encode image
24
+ buffer = BytesIO()
25
+ image.save(buffer, format='PNG')
26
+ img_b64 = base64.b64encode(buffer.getvalue()).decode()
27
+
28
+ # Send to LM Studio
29
+ start_time = time.time()
30
+ response = requests.post(
31
+ "http://192.168.0.105:1234/v1/chat/completions",
32
+ headers={"Content-Type": "application/json"},
33
+ json={
34
+ "model": "google/gemma-3-4b",
35
+ "messages": [
36
+ {
37
+ "role": "user",
38
+ "content": [
39
+ {"type": "text", "text": prompt},
40
+ {"type": "image_url", "image_url": {"url": f"data:image/png;base64,{img_b64}"}}
41
+ ]
42
+ }
43
+ ],
44
+ "max_tokens": 500,
45
+ "temperature": 0.3
46
+ },
47
+ timeout=30
48
+ )
49
+
50
+ if response.status_code == 200:
51
+ result = response.json()
52
+ content = result["choices"][0]["message"]["content"]
53
+ response_time = time.time() - start_time
54
+ return f"Analysis ({response_time:.1f}s):\n\n{content}"
55
+ else:
56
+ return f"Error: HTTP {response.status_code}"
57
+
58
+ except Exception as e:
59
+ return f"Error: {str(e)}"
60
+
61
+ def create_test_image():
62
+ """Create a simple test image"""
63
+ img = Image.new('RGB', (224, 224), color='white')
64
+ draw = ImageDraw.Draw(img)
65
+ draw.rectangle([50, 50, 174, 174], fill='red', outline='black', width=2)
66
+ draw.ellipse([87, 87, 137, 137], fill='blue')
67
+ draw.text((10, 10), "LOGOS", fill='black')
68
+ return img
69
+
70
+ def test_connection():
71
+ """Test LM Studio connection"""
72
+ try:
73
+ response = requests.post(
74
+ "http://192.168.0.105:1234/v1/chat/completions",
75
+ headers={"Content-Type": "application/json"},
76
+ json={
77
+ "model": "google/gemma-3-4b",
78
+ "messages": [{"role": "user", "content": "Say 'Connection test successful'"}],
79
+ "max_tokens": 10
80
+ },
81
+ timeout=10
82
+ )
83
+
84
+ if response.status_code == 200:
85
+ result = response.json()
86
+ content = result["choices"][0]["message"]["content"]
87
+ return f"Connected: {content}"
88
+ else:
89
+ return f"Connection failed: HTTP {response.status_code}"
90
+
91
+ except Exception as e:
92
+ return f"Connection error: {str(e)}"
93
+
94
+ # Create Gradio interface
95
+ with gr.Blocks(title="LOGOS Computational System") as interface:
96
+
97
+ gr.HTML("""
98
+ <div style="text-align: center; padding: 20px; background: linear-gradient(135deg, #667eea 0%, #764ba2 100%); color: white; border-radius: 10px; margin-bottom: 20px;">
99
+ <h1>LOGOS Computational System</h1>
100
+ <p>Vision Analysis with LM Studio Integration</p>
101
+ </div>
102
+ """)
103
+
104
+ with gr.Row():
105
+ with gr.Column(scale=2):
106
+ # Input section
107
+ gr.Markdown("## Image Analysis")
108
+
109
+ with gr.Row():
110
+ image_input = gr.Image(
111
+ label="Upload Image",
112
+ type="pil",
113
+ height=300
114
+ )
115
+
116
+ with gr.Column():
117
+ gr.Button("Create Test Image").click(
118
+ fn=create_test_image,
119
+ outputs=image_input
120
+ )
121
+
122
+ prompt_input = gr.Textbox(
123
+ label="Analysis Prompt",
124
+ value="Analyze this image in detail",
125
+ lines=3
126
+ )
127
+
128
+ analyze_btn = gr.Button("Analyze Image", variant="primary", size="lg")
129
+
130
+ # Output
131
+ result_output = gr.Textbox(
132
+ label="Analysis Result",
133
+ lines=12,
134
+ interactive=False
135
+ )
136
+
137
+ analyze_btn.click(
138
+ fn=analyze_image,
139
+ inputs=[image_input, prompt_input],
140
+ outputs=result_output
141
+ )
142
+
143
+ with gr.Column(scale=1):
144
+ # Status section
145
+ gr.Markdown("## System Status")
146
+
147
+ with gr.Row():
148
+ conn_btn = gr.Button("Test Connection", size="sm")
149
+ conn_result = gr.Textbox(label="Connection Test", lines=2)
150
+
151
+ conn_btn.click(
152
+ fn=test_connection,
153
+ outputs=conn_result
154
+ )
155
+
156
+ gr.Markdown("## Configuration")
157
+ gr.JSON(
158
+ value={
159
+ "lm_studio_url": "http://192.168.0.105:1234",
160
+ "model": "google/gemma-3-4b"
161
+ },
162
+ label="System Config"
163
+ )
164
+
165
+ if __name__ == "__main__":
166
+ print("Starting LOGOS Hugging Face Space...")
167
+ print("URL: http://localhost:7860")
168
+ print("Model: google/gemma-3-4b")
169
+ print("LM Studio: http://192.168.0.105:1234")
170
+ print()
171
+
172
+ interface.launch(
173
+ server_name="0.0.0.0",
174
+ server_port=7860,
175
+ share=False,
176
+ show_error=True
177
+ )
hf_space_minimal/requirements.txt ADDED
@@ -0,0 +1,4 @@
 
 
 
 
 
1
+ gradio>=4.0.0
2
+ requests>=2.28.0
3
+ Pillow>=9.0.0
4
+ numpy>=1.21.0