import gradio as gr import requests def chat_with_gpt3_via_fastapi(prompt): # Make sure the URL matches your FastAPI server's address and the correct endpoint response = requests.get("http://127.0.0.1:8000/chat/", json={"?prompt": prompt}) if response.status_code == 200: return response.json()["response"] else: return f"Error: {response.status_code}, {response.text}" interface = gr.Interface( fn=chat_with_gpt3_via_fastapi, inputs=gr.Textbox(lines=2, placeholder="Enter your message here..."), outputs="text", title="GPT-3.5 Turbo Chatbot with FastAPI", description="This chatbot uses a FastAPI backend to communicate with OpenAI's GPT-3.5 Turbo.", ) if __name__ == "__main__": interface.launch()