-
-
Save shawnhank/f185d047d8d0d98602447b9e66225de7 to your computer and use it in GitHub Desktop.
OpenChat Code
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import requests | |
import json | |
import gradio as gr | |
url = "http://localhost:11434/api/generate" | |
headers = { | |
'Content-Type': 'application/json', | |
} | |
conversation_history = [] | |
def generate_response(prompt): | |
conversation_history.append(prompt) | |
full_prompt = "\n".join(conversation_history) | |
data = { | |
"model": "mistral", | |
"stream": False, | |
"prompt": full_prompt, | |
} | |
response = requests.post(url, headers=headers, data=json.dumps(data)) | |
if response.status_code == 200: | |
response_text = response.text | |
data = json.loads(response_text) | |
actual_response = data["response"] | |
conversation_history.append(actual_response) | |
return actual_response | |
else: | |
print("Error:", response.status_code, response.text) | |
return None | |
iface = gr.Interface( | |
fn=generate_response, | |
inputs=gr.inputs.Textbox(lines=2, placeholder="Enter your prompt here..."), | |
outputs="text" | |
) | |
iface.launch() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment