Spaces:
Runtime error
Runtime error
File size: 2,223 Bytes
518640f 36c08b7 518640f |
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 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# Import the required libraries
import streamlit as st
from phi.assistant import Assistant
from phi.tools.arxiv_toolkit import ArxivToolkit
from huggingface_hub import InferenceClient
# Initialize the Hugging Face Inference Client
client = InferenceClient(model="HuggingFaceH4/zephyr-7b-beta")
# Set up the Streamlit app
st.set_page_config(page_title="Chat with Research Papers", layout="wide")
st.title("Chat with Research Papers 🔎🤖")
st.caption("This app allows you to chat with arXiv research papers using the Zephyr model hosted on Hugging Face.")
# Sidebar Configuration
st.sidebar.header("Settings")
temperature = st.sidebar.slider("Temperature", 0.0, 1.0, 0.7, 0.1)
top_p = st.sidebar.slider("Top-p", 0.0, 1.0, 0.95, 0.05)
max_tokens = st.sidebar.slider("Max Tokens", 100, 1024, 512, 50)
# Initialize Assistant with Arxiv Toolkit
assistant = Assistant(llm=client, tools=[ArxivToolkit()])
# Get the search query from the user
query = st.text_input("Enter your research query or topic:")
if st.button("Search") and query:
with st.spinner("Searching arXiv and generating a response..."):
# Prepare messages for the chat
messages = [
{"role": "system", "content": "You are a helpful assistant for arXiv research."},
{"role": "user", "content": query}
]
# Generate response using Zephyr
response = ""
for message in client.chat_completion(messages, max_tokens=max_tokens, stream=True, temperature=temperature, top_p=top_p):
token = message.choices[0].delta.content
response += token
# Search arXiv and parse results
arxiv_results = assistant.run(f"Search arxiv for '{query}'", stream=False)
# Display the response
st.subheader("Model Response")
st.write(response)
# Display arXiv results
st.subheader("ArXiv Search Results")
if arxiv_results:
for paper in arxiv_results:
with st.expander(paper['title']):
st.write(f"**Authors:** {', '.join(paper['authors'])}")
st.write(f"**Abstract:** {paper['summary']}")
st.write(f"[Read More]({paper['link']})")
else:
st.write("No results found.")
|