Spaces:
Runtime error
Runtime error
Daniel commited on
Commit ·
5b92634
1
Parent(s): d5d236b
Dummy API
Browse files- .gitignore +3 -0
- app.py +13 -1
- models/dialogue.py +26 -0
.gitignore
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
.DS_Store
|
| 2 |
+
**/__pycache__/
|
| 3 |
+
.env
|
app.py
CHANGED
|
@@ -1,7 +1,19 @@
|
|
| 1 |
-
from fastapi import FastAPI
|
|
|
|
|
|
|
|
|
|
| 2 |
|
| 3 |
app = FastAPI()
|
| 4 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 5 |
@app.get("/")
|
| 6 |
def greet_json():
|
| 7 |
return {"Hello": "World!"}
|
|
|
|
| 1 |
+
from fastapi import FastAPI, HTTPException
|
| 2 |
+
from models.dialogue import DialogueInput, DialogueResponse
|
| 3 |
+
import logging
|
| 4 |
+
import random
|
| 5 |
|
| 6 |
app = FastAPI()
|
| 7 |
|
| 8 |
+
@app.post("/process", response_model=DialogueResponse)
|
| 9 |
+
async def process_input(dialogue: DialogueInput):
|
| 10 |
+
logging.info(f"Received input: {dialogue.Input} id: {dialogue.IdPieza}") # "Received input: " + dialogue.Input + dialog.IdPieza
|
| 11 |
+
user_input = dialogue.Input
|
| 12 |
+
decision = random.choice([True, False])
|
| 13 |
+
response = f"Echo: {user_input} /nAnswer: {'Yes' if decision else 'No'}"
|
| 14 |
+
return DialogueResponse(Response=response, Decision=decision)
|
| 15 |
+
|
| 16 |
+
|
| 17 |
@app.get("/")
|
| 18 |
def greet_json():
|
| 19 |
return {"Hello": "World!"}
|
models/dialogue.py
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from pydantic import BaseModel
|
| 2 |
+
|
| 3 |
+
class DialogueInput(BaseModel):
|
| 4 |
+
Input: str
|
| 5 |
+
IdPieza: int
|
| 6 |
+
Language: str
|
| 7 |
+
|
| 8 |
+
class AudioDialogueInput(BaseModel):
|
| 9 |
+
AudioPath: str
|
| 10 |
+
IdPieza: int
|
| 11 |
+
Language: str
|
| 12 |
+
|
| 13 |
+
class DialogueResponse(BaseModel):
|
| 14 |
+
Response: str
|
| 15 |
+
Decision: bool
|
| 16 |
+
|
| 17 |
+
class ReponseToAudio(BaseModel):
|
| 18 |
+
Transcription: str
|
| 19 |
+
SpeakerLanguage: str
|
| 20 |
+
SpeakerAccent: str
|
| 21 |
+
DialogueResponse: DialogueResponse
|
| 22 |
+
|
| 23 |
+
class DialogueResponseWithTranscription(BaseModel):
|
| 24 |
+
Response: str
|
| 25 |
+
Decision: bool
|
| 26 |
+
Transcription: str
|