Spaces:
Sleeping
Sleeping
Upload 3 files
Browse files- Dockerfile +16 -0
- main.py +43 -0
- requirements.txt +12 -0
Dockerfile
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Use official Python 3.12.4 image
|
| 2 |
+
FROM python:3.12.4-slim
|
| 3 |
+
|
| 4 |
+
# FROM python:3.9
|
| 5 |
+
|
| 6 |
+
RUN useradd -m -u 1000 user
|
| 7 |
+
USER user
|
| 8 |
+
ENV PATH="/home/user/.local/bin:$PATH"
|
| 9 |
+
|
| 10 |
+
WORKDIR /app
|
| 11 |
+
|
| 12 |
+
COPY --chown=user ./requirements.txt requirements.txt
|
| 13 |
+
RUN pip install --no-cache-dir --upgrade -r requirements.txt
|
| 14 |
+
|
| 15 |
+
COPY --chown=user . /app
|
| 16 |
+
CMD ["gunicorn","-b", "0.0.0.0:7860", "main:app"]
|
main.py
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from flask import Flask, request, jsonify
|
| 2 |
+
import google.generativeai as genai
|
| 3 |
+
import os
|
| 4 |
+
|
| 5 |
+
# Configure API key
|
| 6 |
+
GOOGLE_API_KEY = "AIzaSyAbr-HbJamF1hrZOMaKPMiiXQxRgEd0o4g" # Or hardcode for testing
|
| 7 |
+
genai.configure(api_key=GOOGLE_API_KEY)
|
| 8 |
+
|
| 9 |
+
# Initialize model
|
| 10 |
+
model = genai.GenerativeModel("gemini-pro")
|
| 11 |
+
|
| 12 |
+
Medical_prompt = """you are sahha chatbot ,You are a knowledgeable medical expert. Analyze the provided medical input and generate a comprehensive, informative response that addresses the patient's query or medical scenario.
|
| 13 |
+
### Input:
|
| 14 |
+
{input_text}
|
| 15 |
+
### Response:
|
| 16 |
+
"""
|
| 17 |
+
|
| 18 |
+
def generate_response(input_text):
|
| 19 |
+
prompt = Medical_prompt.format(input_text=input_text)
|
| 20 |
+
try:
|
| 21 |
+
response = model.generate_content(prompt)
|
| 22 |
+
return response.text.strip()
|
| 23 |
+
except Exception as e:
|
| 24 |
+
return f"❌ Error: {str(e)}"
|
| 25 |
+
|
| 26 |
+
app = Flask(__name__)
|
| 27 |
+
|
| 28 |
+
@app.route('/', methods=['GET'])
|
| 29 |
+
def home():
|
| 30 |
+
return "✅ Sahha chatbot using Gemini is Running", 200
|
| 31 |
+
|
| 32 |
+
@app.route('/Q&A', methods=['POST'])
|
| 33 |
+
def QandAnswer():
|
| 34 |
+
try:
|
| 35 |
+
user_input = request.json.get('input_text')
|
| 36 |
+
if not user_input:
|
| 37 |
+
return jsonify({'error': 'Missing input_text'}), 400
|
| 38 |
+
|
| 39 |
+
response = generate_response(user_input)
|
| 40 |
+
return jsonify({'Answers': response})
|
| 41 |
+
|
| 42 |
+
except Exception as e:
|
| 43 |
+
return jsonify({'error': str(e)}), 500
|
requirements.txt
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
Flask==3.1.1
|
| 2 |
+
google-generativeai==0.4.1
|
| 3 |
+
gunicorn==21.2.0
|
| 4 |
+
certifi==2025.4.26
|
| 5 |
+
charset-normalizer==3.4.2
|
| 6 |
+
idna==3.10
|
| 7 |
+
requests==2.32.3
|
| 8 |
+
urllib3==2.4.0
|
| 9 |
+
Werkzeug==3.1.3
|
| 10 |
+
Jinja2==3.1.6
|
| 11 |
+
MarkupSafe==3.0.2
|
| 12 |
+
itsdangerous==2.2.0
|