goldfishsoftwarelabs commited on
Commit
83ff9b0
·
verified ·
1 Parent(s): cca95e9

Rename main.py to app.py

Browse files
Files changed (2) hide show
  1. app.py +42 -0
  2. main.py +0 -56
app.py ADDED
@@ -0,0 +1,42 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from fastapi import FastAPI, HTTPException
2
+ import requests
3
+ import json
4
+
5
+ app = FastAPI()
6
+
7
+ # Ollama API endpoint (running inside the container)
8
+ OLLAMA_API = "http://localhost:11434/api/generate"
9
+
10
+ @app.get("/")
11
+ async def root():
12
+ return {"message": "Welcome to the custom LLM API for Qwen3-4B RPG Roleplay"}
13
+
14
+ @app.post("/generate")
15
+ async def generate(prompt: str):
16
+ try:
17
+ # Send request to Ollama API
18
+ payload = {
19
+ "model": "hf.co/Chun121/qwen3-4B-rpg-roleplay:Q4_K_M",
20
+ "prompt": prompt,
21
+ "stream": False
22
+ }
23
+ response = requests.post(OLLAMA_API, json=payload)
24
+ response.raise_for_status()
25
+ return response.json()
26
+ except requests.RequestException as e:
27
+ raise HTTPException(status_code=500, detail=f"Error communicating with Ollama: {str(e)}")
28
+
29
+ # Optional: Add more endpoints as needed
30
+ @app.post("/chat")
31
+ async def chat(prompt: str, context: str = ""):
32
+ try:
33
+ payload = {
34
+ "model": "hf.co/Chun121/qwen3-4B-rpg-roleplay:Q4_K_M",
35
+ "prompt": f"{context}\nUser: {prompt}",
36
+ "stream": False
37
+ }
38
+ response = requests.post(OLLAMA_API, json=payload)
39
+ response.raise_for_status()
40
+ return response.json()
41
+ except requests.RequestException as e:
42
+ raise HTTPException(status_code=500, detail=f"Error communicating with Ollama: {str(e)}")
main.py DELETED
@@ -1,56 +0,0 @@
1
- from fastapi import FastAPI, File, UploadFile, HTTPException
2
- from fastapi.responses import JSONResponse
3
- from PIL import Image
4
- import io
5
- import random
6
-
7
- app = FastAPI()
8
-
9
- @app.post("/analyze-medical-image/")
10
- async def analyze_medical_image(file: UploadFile = File(...)):
11
- # Validate file type
12
- if not file.content_type.startswith("image/"):
13
- raise HTTPException(status_code=400, detail="File must be an image")
14
-
15
- try:
16
- # Read and validate image
17
- contents = await file.read()
18
- image = Image.open(io.BytesIO(contents))
19
-
20
- # Mock medical image analysis
21
- mock_results = {
22
- "image_size": image.size,
23
- "format": image.format,
24
- "mock_diagnosis": random.choice([
25
- "Normal",
26
- "Pneumonia",
27
- "Fracture",
28
- "Tumor",
29
- "Inflammation"
30
- ]),
31
- "mock_confidence": round(random.uniform(0.65, 0.95), 2),
32
- "mock_details": {
33
- "region_of_interest": random.choice(["Lung", "Bone", "Brain", "Liver", "None"]),
34
- "severity": random.choice(["Mild", "Moderate", "Severe"]),
35
- "processing_time_ms": random.randint(200, 600),
36
- "recommendation": random.choice([
37
- "Further testing required",
38
- "Consult specialist",
39
- "Monitor condition",
40
- "Immediate treatment advised"
41
- ])
42
- }
43
- }
44
-
45
- return JSONResponse(content={
46
- "status": "success",
47
- "results": mock_results,
48
- "message": "Medical image processed successfully"
49
- })
50
-
51
- except Exception as e:
52
- raise HTTPException(status_code=500, detail=f"Error processing image: {str(e)}")
53
-
54
- @app.get("/health")
55
- async def health_check():
56
- return {"status": "healthy"}