Spaces:
Sleeping
Sleeping
Upload 4 files
Browse files- app/index.html +115 -0
- app/main.py +10 -5
- files/empty.txt +1 -0
app/index.html
ADDED
|
@@ -0,0 +1,115 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<!DOCTYPE html>
|
| 2 |
+
<html lang="en">
|
| 3 |
+
<head>
|
| 4 |
+
|
| 5 |
+
<meta charset="UTF-8">
|
| 6 |
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
| 7 |
+
<link rel="preconnect" href="https://fonts.googleapis.com">
|
| 8 |
+
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
|
| 9 |
+
<link href="https://fonts.googleapis.com/css2?family=Lato:wght@700;900&family=Rubik&display=swap" rel="stylesheet">
|
| 10 |
+
<title >Emotion Detection API</title>
|
| 11 |
+
<style>
|
| 12 |
+
body {
|
| 13 |
+
font-family: 'Rubik', sans-serif;;
|
| 14 |
+
margin: 0;
|
| 15 |
+
padding: 0;
|
| 16 |
+
background-color: #ecf0f1;
|
| 17 |
+
color: #2c3e50;
|
| 18 |
+
}
|
| 19 |
+
|
| 20 |
+
header {
|
| 21 |
+
text-align: center;
|
| 22 |
+
padding: 20px;
|
| 23 |
+
background-color: #8e44ad;
|
| 24 |
+
color: #fff;
|
| 25 |
+
border-bottom-left-radius: 10px;
|
| 26 |
+
border-bottom-right-radius: 10px;
|
| 27 |
+
}
|
| 28 |
+
|
| 29 |
+
section {
|
| 30 |
+
max-width: 800px;
|
| 31 |
+
margin: 20px auto;
|
| 32 |
+
padding: 20px;
|
| 33 |
+
background-color: #fff;
|
| 34 |
+
border: 1px solid #bdc3c7;
|
| 35 |
+
border-radius: 10px;
|
| 36 |
+
}
|
| 37 |
+
title {
|
| 38 |
+
color: white;
|
| 39 |
+
font-size: xx-large;
|
| 40 |
+
}
|
| 41 |
+
|
| 42 |
+
h1 {
|
| 43 |
+
color: #8e44ad;
|
| 44 |
+
font-size: 2em; /* Increased font size */
|
| 45 |
+
}
|
| 46 |
+
|
| 47 |
+
h2 {
|
| 48 |
+
color: #8e44ad;
|
| 49 |
+
}
|
| 50 |
+
h3 {
|
| 51 |
+
color: white;
|
| 52 |
+
font-size: xx-large;
|
| 53 |
+
padding: auto;
|
| 54 |
+
font-weight: bold;
|
| 55 |
+
font-family: 'Rubik', sans-serif;
|
| 56 |
+
}
|
| 57 |
+
a {
|
| 58 |
+
display: inline-block;
|
| 59 |
+
padding: 10px 20px;
|
| 60 |
+
margin-top: 10px;
|
| 61 |
+
background-color: #8e44ad;
|
| 62 |
+
color: #fff;
|
| 63 |
+
text-decoration: none;
|
| 64 |
+
border-radius: 5px;
|
| 65 |
+
transition: background-color 0.3s;
|
| 66 |
+
}
|
| 67 |
+
|
| 68 |
+
a:hover {
|
| 69 |
+
background-color: #2980b9;
|
| 70 |
+
color:white;
|
| 71 |
+
}
|
| 72 |
+
footer {
|
| 73 |
+
text-align: center;
|
| 74 |
+
padding: 10px;
|
| 75 |
+
background-color: #8e44ad;
|
| 76 |
+
color: #fff;
|
| 77 |
+
border-top-left-radius: 10px;
|
| 78 |
+
border-top-right-radius: 10px;
|
| 79 |
+
}
|
| 80 |
+
|
| 81 |
+
/* Added the following CSS rule to make content bold */
|
| 82 |
+
section p {
|
| 83 |
+
font-weight: bold;
|
| 84 |
+
font-family: 'Rubik', sans-serif;
|
| 85 |
+
}
|
| 86 |
+
</style>
|
| 87 |
+
</head>
|
| 88 |
+
<body>
|
| 89 |
+
<header>
|
| 90 |
+
<h3>Emotion Detection API</h3>
|
| 91 |
+
<h3 style="font-size: medium;">Analyzing emotions through text</h3>
|
| 92 |
+
</header>
|
| 93 |
+
|
| 94 |
+
<section>
|
| 95 |
+
<h2>About</h2>
|
| 96 |
+
<p>
|
| 97 |
+
<strong>Welcome to the Emotion Detection API!</strong> Our API provides a powerful tool for analyzing emotions in text. Whether you're working on sentiment analysis, chatbot development, or any application that involves understanding emotions conveyed through text, our API can assist you in recognizing and categorizing emotions effectively.
|
| 98 |
+
</p>
|
| 99 |
+
</section>
|
| 100 |
+
|
| 101 |
+
<section>
|
| 102 |
+
<h2>Documentation</h2>
|
| 103 |
+
<p>
|
| 104 |
+
<strong>For detailed information on how to use the Emotion Detection API, please refer to our documentation.</strong> It provides endpoints, request/response examples, and other essential details to help you get started.
|
| 105 |
+
</p>
|
| 106 |
+
<p>
|
| 107 |
+
<a href="https://sankie005-emotiondetectionapi.hf.space/docs">API Documentation</a>
|
| 108 |
+
</p>
|
| 109 |
+
</section>
|
| 110 |
+
|
| 111 |
+
<footer>
|
| 112 |
+
<p>© 2023 Karen AI</p>
|
| 113 |
+
</footer>
|
| 114 |
+
</body>
|
| 115 |
+
</html>
|
app/main.py
CHANGED
|
@@ -1,10 +1,13 @@
|
|
| 1 |
-
from fastapi import FastAPI, HTTPException
|
| 2 |
from pydantic import BaseModel
|
|
|
|
| 3 |
from typing import List
|
| 4 |
-
import
|
| 5 |
-
|
|
|
|
| 6 |
app = FastAPI()
|
| 7 |
-
|
|
|
|
| 8 |
class TextInput(BaseModel):
|
| 9 |
InputText: str # python casing??????
|
| 10 |
|
|
@@ -13,7 +16,9 @@ def emotion_detection(str1: str) -> str:
|
|
| 13 |
pipe = pipeline(model="distilbert-base-uncased-finetuned-sst-2-english")
|
| 14 |
expected=(pipe(str1))
|
| 15 |
return expected[0].get('label')
|
| 16 |
-
|
|
|
|
|
|
|
| 17 |
@app.post("/generate-emotion/")
|
| 18 |
async def detect_emotion(input_data: TextInput):
|
| 19 |
text1 = input_data.InputText
|
|
|
|
| 1 |
+
from fastapi import FastAPI, HTTPException,APIRouter,Request
|
| 2 |
from pydantic import BaseModel
|
| 3 |
+
from fastapi.responses import HTMLResponse
|
| 4 |
from typing import List
|
| 5 |
+
from fastapi.staticfiles import StaticFiles
|
| 6 |
+
from starlette.responses import FileResponse
|
| 7 |
+
import os
|
| 8 |
app = FastAPI()
|
| 9 |
+
os.environ['SENTENCE_TRANSFORMERS_HOME'] = './.cache' ## For Docker
|
| 10 |
+
app.mount("/files/", StaticFiles(directory="files"), name="index")
|
| 11 |
class TextInput(BaseModel):
|
| 12 |
InputText: str # python casing??????
|
| 13 |
|
|
|
|
| 16 |
pipe = pipeline(model="distilbert-base-uncased-finetuned-sst-2-english")
|
| 17 |
expected=(pipe(str1))
|
| 18 |
return expected[0].get('label')
|
| 19 |
+
@app.get("/")
|
| 20 |
+
async def read_index():
|
| 21 |
+
return FileResponse('index.html')
|
| 22 |
@app.post("/generate-emotion/")
|
| 23 |
async def detect_emotion(input_data: TextInput):
|
| 24 |
text1 = input_data.InputText
|
files/empty.txt
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
this is an empty text file to get it to git commit..
|