Spaces:
Runtime error
Runtime error
Commit
·
2ff2948
1
Parent(s):
7020549
Update app.py
Browse files
app.py
CHANGED
|
@@ -22,7 +22,6 @@ import scripts.twitter_scraper as ts
|
|
| 22 |
import scripts.utils as utils
|
| 23 |
from scripts import generative
|
| 24 |
import nltk
|
| 25 |
-
import pandas as pd
|
| 26 |
|
| 27 |
logging.basicConfig(level=logging.INFO)
|
| 28 |
|
|
@@ -54,22 +53,26 @@ async def webpage(request: Request):
|
|
| 54 |
|
| 55 |
@app.get("/accounts")
|
| 56 |
def get_accounts() -> List[dict]:
|
|
|
|
|
|
|
| 57 |
logging.info(f"Pulling account information on {username_list}")
|
| 58 |
account_info_list = [
|
| 59 |
ts.get_twitter_account_info(twitter_handle=account) for account in username_list
|
| 60 |
]
|
| 61 |
df_account = pd.DataFrame(account_info_list)
|
| 62 |
-
df_account = df_account.style.bar(
|
| 63 |
-
|
| 64 |
-
|
| 65 |
-
|
| 66 |
-
|
|
|
|
|
|
|
| 67 |
|
| 68 |
|
| 69 |
@app.get("/tweets/{username}", response_model=dict)
|
| 70 |
def get_tweets(username: str) -> dict:
|
| 71 |
if username in username_list:
|
| 72 |
-
#query = f"from:{username} since:{start_date} until:{end_date}"
|
| 73 |
return ts.get_tweets(query=query)
|
| 74 |
else:
|
| 75 |
return {"detail": "Account not in scope of project."}
|
|
@@ -202,18 +205,21 @@ async def generate_text(request: Request):
|
|
| 202 |
|
| 203 |
return {"generated_text": final_text}
|
| 204 |
|
|
|
|
| 205 |
@app.get("/examples1")
|
| 206 |
async def read_examples():
|
| 207 |
with open("templates/charts/handle_sentiment_breakdown.html") as f:
|
| 208 |
html = f.read()
|
| 209 |
return HTMLResponse(content=html)
|
| 210 |
|
|
|
|
| 211 |
@app.get("/examples2")
|
| 212 |
async def read_examples():
|
| 213 |
with open("templates/charts/handle_sentiment_timesteps.html") as f:
|
| 214 |
html = f.read()
|
| 215 |
return HTMLResponse(content=html)
|
| 216 |
|
|
|
|
| 217 |
# if __name__ == "__main__":
|
| 218 |
# # uvicorn.run(app, host="0.0.0.0", port=8000)
|
| 219 |
# uvicorn.run("app:app", host="127.0.0.1", port=5049, reload=True)
|
|
|
|
| 22 |
import scripts.utils as utils
|
| 23 |
from scripts import generative
|
| 24 |
import nltk
|
|
|
|
| 25 |
|
| 26 |
logging.basicConfig(level=logging.INFO)
|
| 27 |
|
|
|
|
| 53 |
|
| 54 |
@app.get("/accounts")
|
| 55 |
def get_accounts() -> List[dict]:
|
| 56 |
+
import pandas as pd
|
| 57 |
+
|
| 58 |
logging.info(f"Pulling account information on {username_list}")
|
| 59 |
account_info_list = [
|
| 60 |
ts.get_twitter_account_info(twitter_handle=account) for account in username_list
|
| 61 |
]
|
| 62 |
df_account = pd.DataFrame(account_info_list)
|
| 63 |
+
df_account = df_account.style.bar(
|
| 64 |
+
subset=["follower_count", "friends_count"], color="#d65f5f"
|
| 65 |
+
)
|
| 66 |
+
df_account = df_account.format(
|
| 67 |
+
{"follower_count": "{:,.0f}", "friends_count": "{:,.0f}"}
|
| 68 |
+
)
|
| 69 |
+
return HTMLResponse(content=df_account.to_html(classes="center"), status_code=200)
|
| 70 |
|
| 71 |
|
| 72 |
@app.get("/tweets/{username}", response_model=dict)
|
| 73 |
def get_tweets(username: str) -> dict:
|
| 74 |
if username in username_list:
|
| 75 |
+
# query = f"from:{username} since:{start_date} until:{end_date}"
|
| 76 |
return ts.get_tweets(query=query)
|
| 77 |
else:
|
| 78 |
return {"detail": "Account not in scope of project."}
|
|
|
|
| 205 |
|
| 206 |
return {"generated_text": final_text}
|
| 207 |
|
| 208 |
+
|
| 209 |
@app.get("/examples1")
|
| 210 |
async def read_examples():
|
| 211 |
with open("templates/charts/handle_sentiment_breakdown.html") as f:
|
| 212 |
html = f.read()
|
| 213 |
return HTMLResponse(content=html)
|
| 214 |
|
| 215 |
+
|
| 216 |
@app.get("/examples2")
|
| 217 |
async def read_examples():
|
| 218 |
with open("templates/charts/handle_sentiment_timesteps.html") as f:
|
| 219 |
html = f.read()
|
| 220 |
return HTMLResponse(content=html)
|
| 221 |
|
| 222 |
+
# uvicorn --workers=2 app:app
|
| 223 |
# if __name__ == "__main__":
|
| 224 |
# # uvicorn.run(app, host="0.0.0.0", port=8000)
|
| 225 |
# uvicorn.run("app:app", host="127.0.0.1", port=5049, reload=True)
|