Spaces:
Running
Running
Update main.py
Browse files
main.py
CHANGED
|
@@ -4,9 +4,15 @@ from fastapi import FastAPI
|
|
| 4 |
from pydantic import BaseModel
|
| 5 |
import re
|
| 6 |
import os
|
| 7 |
-
|
|
|
|
| 8 |
|
| 9 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 10 |
|
| 11 |
|
| 12 |
app = FastAPI()
|
|
@@ -107,7 +113,7 @@ async def root(item: Item):
|
|
| 107 |
|
| 108 |
article = extract_article_content(item.url)
|
| 109 |
|
| 110 |
-
output =
|
| 111 |
|
| 112 |
return {"summary": output}
|
| 113 |
|
|
|
|
| 4 |
from pydantic import BaseModel
|
| 5 |
import re
|
| 6 |
import os
|
| 7 |
+
import transformers
|
| 8 |
+
import torch
|
| 9 |
|
| 10 |
+
|
| 11 |
+
model_id = "meta-llama/Meta-Llama-3-8B"
|
| 12 |
+
|
| 13 |
+
pipeline = transformers.pipeline(
|
| 14 |
+
"text-generation", model=model_id, model_kwargs={"torch_dtype": torch.bfloat16}, device_map="auto"
|
| 15 |
+
)
|
| 16 |
|
| 17 |
|
| 18 |
app = FastAPI()
|
|
|
|
| 113 |
|
| 114 |
article = extract_article_content(item.url)
|
| 115 |
|
| 116 |
+
output = pipeline("Summarize the following news article for me:", article)
|
| 117 |
|
| 118 |
return {"summary": output}
|
| 119 |
|