#conda create -n gradioenv #conda activate gradioenv #conda install -c conda-forge gradio #don't forget to set conda env as interpreter in VS Code import requests, json import gradio as gr model = 'phi3' #llama3 context = [] import gradio as gr #Call Ollama API def generate(prompt, context, top_k, top_p, temp): r = requests.post('http://localhost:11434/api/generate', json={ 'model': model, 'prompt': prompt, 'context': context, 'options':{ 'top_k': top_k, 'temperature':top_p, 'top_p': temp } }, stream=False) r.raise_for_status() response = "" for line in r.iter_lines(): body = json.loads(line) response_part = body.get('response', '') print(response_part) if 'error' in body: raise Exception(body['error']) response += response_part if body.get('done', False): context = body.get('context', []) return response, context def chat(input, chat_history, top_k, top_p, temp): chat_history = chat_history or [] global context output, context = generate(input, context, top_k, top_p, temp) chat_history.append((input, output)) return chat_history, chat_history #the first history in return history, history is meant to update the #chatbot widget, and the second history is meant to update the state #(which is used to maintain conversation history across interactions) #########################Gradio Code########################## block = gr.Blocks() with block: gr.Markdown("""