File size: 1,519 Bytes
9c5e00f
d53739c
00ca433
9c5e00f
 
 
 
6424758
 
 
546aff0
 
 
00ca433
312f9a4
6424758
9c5e00f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
# Import necessary libraries
from transformers import AutoModel, AutoTokenizer
import streamlit as st
import PyPDF2
import pytesseract
from PIL import Image

# Your Hugging Face access token
access_token = "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"

# Correct model name or path
model_name = "bigcode/starcoderplus"

# Load model and tokenizer
model = AutoModel.from_pretrained(model_name, use_auth_token=access_token)
tokenizer = AutoTokenizer.from_pretrained(model_name, use_auth_token=access_token)

# Streamlit app
st.title("Conversational AI Chatbot")

# User input for code-related question
user_input = st.text_input("Enter your code-related question:")
if user_input:
    # Tokenize and generate code
    inputs = tokenizer(user_input, return_tensors="pt")
    outputs = model.generate(**inputs)
    code = tokenizer.decode(outputs[0])
    st.code(code) # Display the generated code

# User input for PDF reading
pdf_file = st.file_uploader("Upload a PDF file:", type=["pdf"])
if pdf_file:
    pdf_reader = PyPDF2.PdfFileReader(pdf_file)
    pdf_text = ""
    for page_num in range(pdf_reader.numPages):
        page = pdf_reader.getPage(page_num)
        pdf_text += page.extractText()
    st.text(pdf_text) # Display the extracted text

# User input for OCR (image to text)
image_file = st.file_uploader("Upload an image for OCR:", type=["png", "jpg", "jpeg"])
if image_file:
    image = Image.open(image_file)
    ocr_text = pytesseract.image_to_string(image)
    st.text(ocr_text) # Display the extracted text