File size: 832 Bytes
c0a983b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import requests
import streamlit as st
# from streamlitui import StreamlitUI

# stui = StreamlitUI(api_url="http://localhost:8000")  # FastAPI backend URL
st.title("FastAPI ChatBot") 

if "messages" not in st.session_state:
    st.session_state.messages = [] 

for message in st.session_state.messages:
    with st.chat_message(message["role"]):
        st.markdown(message["content"]) 

if prompt := st.chat_input("Write your prompt in this input field"): 
    st.session_state.messages.append({"role": "user", "content": prompt}) 

    with st.chat_message("user"):
        st.text(prompt) 

    response = requests.get(
        f"https://ahmed-eisa-genai-service.hf.space//generate/text", params={"prompt": prompt}
    ) 
    response.raise_for_status() 

    with st.chat_message("assistant"):
        st.markdown(response.text)