step 1: get data using openai api modal and convert into json format in view.py
nutrition = response_nutrition.choices[0].text
parsed_message_nutrition = nutrition .split("\n")
@csrf_exempt
def paneer_form(request):
nutrition_value = "Generate nutrition values for a paneer"
response_nutrition = openai.Completion.create(
engine='text-davinci-003',
prompt=nutrition_value,
max_tokens=120,
temperature=0.3,
top_p=1.0,
frequency_penalty=0.0,
presence_penalty=0.0
)
if response_nutrition.choices:
generated_message_nutrition = response_nutrition.choices[0].text
parsed_message_nutrition = generated_message_nutrition.split("\n")
context = {'paneer': parsed_message,'paneer_about': generated_message_about,'paneer_nutrition': parsed_message_nutrition}
print(parsed_message_nutrition)
return render(request, 'openai/dashboard.html', context)
In template file
<table>
<thead>
<tr>
<h4>Nutrition Value:</h4>
</tr>
</thead>
<tbody>
{% for step in paneer_nutrition %}
<tr>
<td>{{ step }}</td>
</tr>
{% endfor %}
</tbody>
</table>
output
Top comments (0)