Zack Saadioui
8/27/2024
1
ollama version
1
2
3
bash
mkdir ai-survey-tool
cd ai-survey-tool
1
2
3
bash
python -m venv venv
source venv/bin/activate # for Windows use venv\Scripts\activate
1
2
bash
pip install fastapi uvicorn requests
1
main.py
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
from fastapi import FastAPI, HTTPException from pydantic import BaseModel import requests app = FastAPI() class SurveyData(BaseModel): responses: list @app.post("/analyze") async def analyze_survey(data: SurveyData): # Send to Ollama for processing try: response = requests.post( "http://localhost:11434/api/generate", json={"prompt": data.responses} ) response.raise_for_status() return response.json() except requests.RequestException as e: raise HTTPException(status_code=500, detail=str(e)) if __name__ == "__main__": import uvicorn uvicorn.run(app, host="0.0.0.0", port=8000)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
html
<!DOCTYPE html>
<html>
<head>
<title>Survey Analysis Tool</title>
</head>
<body>
<h1>Analyze Your Survey Responses</h1>
<form id="survey-form">
<textarea id="responses" placeholder="Paste your survey responses here..."></textarea><br>
<button type="submit">Analyze</button>
</form>
<div id="results"></div>
<script src="your_script.js"></script>
</body>
</html>
1
your_script.js
Copyright © Arsturn 2024