-
Notifications
You must be signed in to change notification settings - Fork 0
/
model.py
57 lines (45 loc) · 1.77 KB
/
model.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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
import torchvision
import torch
from torchvision.models import resnext101_64x4d, ResNeXt101_64X4D_Weights, densenet201
from torch import nn
from PIL import Image
import numpy as np
import openai
import streamlit as st
openai.api_key = st.secrets["API_KEY"]
class Net(nn.Module):
# def __init__(self, num_classes=101):
# super(Net, self).__init__()
# self.net = resnext101_64x4d(weights=ResNeXt101_64X4D_Weights.DEFAULT,
# progress=True)
# self.net.trainable = False
# self.net.fc = nn.Sequential(nn.Linear(2048, 1024),
# nn.ReLU(),
# nn.Dropout(p=0.3),
# nn.Linear(1024, num_classes))
def __init__(self, num_classes=101):
super(Net, self).__init__()
self.net = densenet201(pretrained=True,progress=True)
self.net.trainable = False
self.net.fc = nn.Sequential(nn.Linear(1000, 512),
nn.LeakyReLU(),
nn.Dropout(p=0.4),
nn.Linear(512, num_classes))
def forward(self, x):
return self.net(x)
# extract content from the file by its absolute path
def extract_file_content(file_path):
with open(file_path, 'r') as file:
content = file.read()
return content.split("\n")[:-1]
def generate_recipe(num_servings, food):
response = openai.Completion.create(
model="text-davinci-003",
prompt="Write a recipe for" + food + "for" + str(num_servings) + "servings",
temperature=0.3,
max_tokens=750,
top_p=1.0,
frequency_penalty=0.0,
presence_penalty=0.0
)
return response["choices"][0]["text"]